1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module atk.TextT; 26 27 public import atk.TextRange; 28 public import atk.c.functions; 29 public import atk.c.types; 30 public import glib.Str; 31 public import glib.c.functions; 32 public import gobject.ObjectG; 33 public import gobject.Signals; 34 public import std.algorithm; 35 36 37 /** 38 * #AtkText should be implemented by #AtkObjects on behalf of widgets 39 * that have text content which is either attributed or otherwise 40 * non-trivial. #AtkObjects whose text content is simple, 41 * unattributed, and very brief may expose that content via 42 * #atk_object_get_name instead; however if the text is editable, 43 * multi-line, typically longer than three or four words, attributed, 44 * selectable, or if the object already uses the 'name' ATK property 45 * for other information, the #AtkText interface should be used to 46 * expose the text content. In the case of editable text content, 47 * #AtkEditableText (a subtype of the #AtkText interface) should be 48 * implemented instead. 49 * 50 * #AtkText provides not only traversal facilities and change 51 * notification for text content, but also caret tracking and glyph 52 * bounding box calculations. Note that the text strings are exposed 53 * as UTF-8, and are therefore potentially multi-byte, and 54 * caret-to-byte offset mapping makes no assumptions about the 55 * character length; also bounding box glyph-to-offset mapping may be 56 * complex for languages which use ligatures. 57 */ 58 public template TextT(TStruct) 59 { 60 /** Get the main Gtk struct */ 61 public AtkText* getTextStruct(bool transferOwnership = false) 62 { 63 if (transferOwnership) 64 ownedRef = false; 65 return cast(AtkText*)getStruct(); 66 } 67 68 69 /** 70 * Adds a selection bounded by the specified offsets. 71 * 72 * Params: 73 * startOffset = the starting character offset of the selected region 74 * endOffset = the offset of the first character after the selected region. 75 * 76 * Returns: %TRUE if successful, %FALSE otherwise 77 */ 78 public bool addSelection(int startOffset, int endOffset) 79 { 80 return atk_text_add_selection(getTextStruct(), startOffset, endOffset) != 0; 81 } 82 83 /** 84 * Get the ranges of text in the specified bounding box. 85 * 86 * Params: 87 * rect = An AtkTextRectangle giving the dimensions of the bounding box. 88 * coordType = Specify whether coordinates are relative to the screen or widget window. 89 * xClipType = Specify the horizontal clip type. 90 * yClipType = Specify the vertical clip type. 91 * 92 * Returns: Array of AtkTextRange. The last 93 * element of the array returned by this function will be NULL. 94 * 95 * Since: 1.3 96 */ 97 public TextRange[] getBoundedRanges(AtkTextRectangle* rect, AtkCoordType coordType, AtkTextClipType xClipType, AtkTextClipType yClipType) 98 { 99 auto __p = atk_text_get_bounded_ranges(getTextStruct(), rect, coordType, xClipType, yClipType); 100 101 if(__p is null) 102 { 103 return null; 104 } 105 106 TextRange[] arr = new TextRange[getArrayLength(__p)]; 107 for(int i = 0; i < getArrayLength(__p); i++) 108 { 109 arr[i] = ObjectG.getDObject!(TextRange)(cast(AtkTextRange*) __p[i]); 110 } 111 112 return arr; 113 } 114 115 /** 116 * Gets the offset of the position of the caret (cursor). 117 * 118 * Returns: the character offset of the position of the caret or -1 if 119 * the caret is not located inside the element or in the case of 120 * any other failure. 121 */ 122 public int getCaretOffset() 123 { 124 return atk_text_get_caret_offset(getTextStruct()); 125 } 126 127 /** 128 * Gets the specified text. 129 * 130 * Params: 131 * offset = a character offset within @text 132 * 133 * Returns: the character at @offset or 0 in the case of failure. 134 */ 135 public dchar getCharacterAtOffset(int offset) 136 { 137 return atk_text_get_character_at_offset(getTextStruct(), offset); 138 } 139 140 /** 141 * Gets the character count. 142 * 143 * Returns: the number of characters or -1 in case of failure. 144 */ 145 public int getCharacterCount() 146 { 147 return atk_text_get_character_count(getTextStruct()); 148 } 149 150 /** 151 * If the extent can not be obtained (e.g. missing support), all of x, y, width, 152 * height are set to -1. 153 * 154 * Get the bounding box containing the glyph representing the character at 155 * a particular text offset. 156 * 157 * Params: 158 * offset = The offset of the text character for which bounding information is required. 159 * x = Pointer for the x coordinate of the bounding box 160 * y = Pointer for the y coordinate of the bounding box 161 * width = Pointer for the width of the bounding box 162 * height = Pointer for the height of the bounding box 163 * coords = specify whether coordinates are relative to the screen or widget window 164 */ 165 public void getCharacterExtents(int offset, out int x, out int y, out int width, out int height, AtkCoordType coords) 166 { 167 atk_text_get_character_extents(getTextStruct(), offset, &x, &y, &width, &height, coords); 168 } 169 170 /** 171 * Creates an #AtkAttributeSet which consists of the default values of 172 * attributes for the text. See the enum AtkTextAttribute for types of text 173 * attributes that can be returned. Note that other attributes may also be 174 * returned. 175 * 176 * Returns: an #AtkAttributeSet which contains the default text 177 * attributes for this #AtkText. This #AtkAttributeSet should be freed by 178 * a call to atk_attribute_set_free(). 179 */ 180 public AtkAttributeSet* getDefaultAttributes() 181 { 182 return atk_text_get_default_attributes(getTextStruct()); 183 } 184 185 /** 186 * Gets the number of selected regions. 187 * 188 * Returns: The number of selected regions, or -1 in the case of failure. 189 */ 190 public int getNSelections() 191 { 192 return atk_text_get_n_selections(getTextStruct()); 193 } 194 195 /** 196 * Gets the offset of the character located at coordinates @x and @y. @x and @y 197 * are interpreted as being relative to the screen or this widget's window 198 * depending on @coords. 199 * 200 * Params: 201 * x = screen x-position of character 202 * y = screen y-position of character 203 * coords = specify whether coordinates are relative to the screen or 204 * widget window 205 * 206 * Returns: the offset to the character which is located at the specified 207 * @x and @y coordinates of -1 in case of failure. 208 */ 209 public int getOffsetAtPoint(int x, int y, AtkCoordType coords) 210 { 211 return atk_text_get_offset_at_point(getTextStruct(), x, y, coords); 212 } 213 214 /** 215 * Get the bounding box for text within the specified range. 216 * 217 * If the extents can not be obtained (e.g. or missing support), the rectangle 218 * fields are set to -1. 219 * 220 * Params: 221 * startOffset = The offset of the first text character for which boundary 222 * information is required. 223 * endOffset = The offset of the text character after the last character 224 * for which boundary information is required. 225 * coordType = Specify whether coordinates are relative to the screen or widget window. 226 * rect = A pointer to a AtkTextRectangle which is filled in by this function. 227 * 228 * Since: 1.3 229 */ 230 public void getRangeExtents(int startOffset, int endOffset, AtkCoordType coordType, out AtkTextRectangle rect) 231 { 232 atk_text_get_range_extents(getTextStruct(), startOffset, endOffset, coordType, &rect); 233 } 234 235 /** 236 * Creates an #AtkAttributeSet which consists of the attributes explicitly 237 * set at the position @offset in the text. @start_offset and @end_offset are 238 * set to the start and end of the range around @offset where the attributes are 239 * invariant. Note that @end_offset is the offset of the first character 240 * after the range. See the enum AtkTextAttribute for types of text 241 * attributes that can be returned. Note that other attributes may also be 242 * returned. 243 * 244 * Params: 245 * offset = the character offset at which to get the attributes, -1 means the offset of 246 * the character to be inserted at the caret location. 247 * startOffset = the address to put the start offset of the range 248 * endOffset = the address to put the end offset of the range 249 * 250 * Returns: an #AtkAttributeSet which contains the attributes 251 * explicitly set at @offset. This #AtkAttributeSet should be freed by 252 * a call to atk_attribute_set_free(). 253 */ 254 public AtkAttributeSet* getRunAttributes(int offset, out int startOffset, out int endOffset) 255 { 256 return atk_text_get_run_attributes(getTextStruct(), offset, &startOffset, &endOffset); 257 } 258 259 /** 260 * Gets the text from the specified selection. 261 * 262 * Params: 263 * selectionNum = The selection number. The selected regions are 264 * assigned numbers that correspond to how far the region is from the 265 * start of the text. The selected region closest to the beginning 266 * of the text region is assigned the number 0, etc. Note that adding, 267 * moving or deleting a selected region can change the numbering. 268 * startOffset = passes back the starting character offset of the selected region 269 * endOffset = passes back the ending character offset (offset immediately past) 270 * of the selected region 271 * 272 * Returns: a newly allocated string containing the selected text. Use g_free() 273 * to free the returned string. 274 */ 275 public string getSelection(int selectionNum, out int startOffset, out int endOffset) 276 { 277 auto retStr = atk_text_get_selection(getTextStruct(), selectionNum, &startOffset, &endOffset); 278 279 scope(exit) Str.freeString(retStr); 280 return Str.toString(retStr); 281 } 282 283 /** 284 * Gets a portion of the text exposed through an #AtkText according to a given @offset 285 * and a specific @granularity, along with the start and end offsets defining the 286 * boundaries of such a portion of text. 287 * 288 * If @granularity is ATK_TEXT_GRANULARITY_CHAR the character at the 289 * offset is returned. 290 * 291 * If @granularity is ATK_TEXT_GRANULARITY_WORD the returned string 292 * is from the word start at or before the offset to the word start after 293 * the offset. 294 * 295 * The returned string will contain the word at the offset if the offset 296 * is inside a word and will contain the word before the offset if the 297 * offset is not inside a word. 298 * 299 * If @granularity is ATK_TEXT_GRANULARITY_SENTENCE the returned string 300 * is from the sentence start at or before the offset to the sentence 301 * start after the offset. 302 * 303 * The returned string will contain the sentence at the offset if the offset 304 * is inside a sentence and will contain the sentence before the offset 305 * if the offset is not inside a sentence. 306 * 307 * If @granularity is ATK_TEXT_GRANULARITY_LINE the returned string 308 * is from the line start at or before the offset to the line 309 * start after the offset. 310 * 311 * If @granularity is ATK_TEXT_GRANULARITY_PARAGRAPH the returned string 312 * is from the start of the paragraph at or before the offset to the start 313 * of the following paragraph after the offset. 314 * 315 * Params: 316 * offset = position 317 * granularity = An #AtkTextGranularity 318 * startOffset = the starting character offset of the returned string, or -1 319 * in the case of error (e.g. invalid offset, not implemented) 320 * endOffset = the offset of the first character after the returned string, 321 * or -1 in the case of error (e.g. invalid offset, not implemented) 322 * 323 * Returns: a newly allocated string containing the text at 324 * the @offset bounded by the specified @granularity. Use g_free() 325 * to free the returned string. Returns %NULL if the offset is invalid 326 * or no implementation is available. 327 * 328 * Since: 2.10 329 */ 330 public string getStringAtOffset(int offset, AtkTextGranularity granularity, out int startOffset, out int endOffset) 331 { 332 auto retStr = atk_text_get_string_at_offset(getTextStruct(), offset, granularity, &startOffset, &endOffset); 333 334 scope(exit) Str.freeString(retStr); 335 return Str.toString(retStr); 336 } 337 338 /** 339 * Gets the specified text. 340 * 341 * Params: 342 * startOffset = a starting character offset within @text 343 * endOffset = an ending character offset within @text, or -1 for the end of the string. 344 * 345 * Returns: a newly allocated string containing the text from @start_offset up 346 * to, but not including @end_offset. Use g_free() to free the returned 347 * string. 348 */ 349 public string getText(int startOffset, int endOffset) 350 { 351 auto retStr = atk_text_get_text(getTextStruct(), startOffset, endOffset); 352 353 scope(exit) Str.freeString(retStr); 354 return Str.toString(retStr); 355 } 356 357 /** 358 * Gets the specified text. 359 * 360 * Deprecated: Please use atk_text_get_string_at_offset() instead. 361 * 362 * Params: 363 * offset = position 364 * boundaryType = An #AtkTextBoundary 365 * startOffset = the starting character offset of the returned string 366 * endOffset = the offset of the first character after the 367 * returned substring 368 * 369 * Returns: a newly allocated string containing the text after @offset bounded 370 * by the specified @boundary_type. Use g_free() to free the returned 371 * string. 372 */ 373 public string getTextAfterOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset) 374 { 375 auto retStr = atk_text_get_text_after_offset(getTextStruct(), offset, boundaryType, &startOffset, &endOffset); 376 377 scope(exit) Str.freeString(retStr); 378 return Str.toString(retStr); 379 } 380 381 /** 382 * Gets the specified text. 383 * 384 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the 385 * offset is returned. 386 * 387 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string 388 * is from the word start at or before the offset to the word start after 389 * the offset. 390 * 391 * The returned string will contain the word at the offset if the offset 392 * is inside a word and will contain the word before the offset if the 393 * offset is not inside a word. 394 * 395 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned 396 * string is from the sentence start at or before the offset to the sentence 397 * start after the offset. 398 * 399 * The returned string will contain the sentence at the offset if the offset 400 * is inside a sentence and will contain the sentence before the offset 401 * if the offset is not inside a sentence. 402 * 403 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned 404 * string is from the line start at or before the offset to the line 405 * start after the offset. 406 * 407 * Deprecated: This method is deprecated since ATK version 408 * 2.9.4. Please use atk_text_get_string_at_offset() instead. 409 * 410 * Params: 411 * offset = position 412 * boundaryType = An #AtkTextBoundary 413 * startOffset = the starting character offset of the returned string 414 * endOffset = the offset of the first character after the 415 * returned substring 416 * 417 * Returns: a newly allocated string containing the text at @offset bounded 418 * by the specified @boundary_type. Use g_free() to free the returned 419 * string. 420 */ 421 public string getTextAtOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset) 422 { 423 auto retStr = atk_text_get_text_at_offset(getTextStruct(), offset, boundaryType, &startOffset, &endOffset); 424 425 scope(exit) Str.freeString(retStr); 426 return Str.toString(retStr); 427 } 428 429 /** 430 * Gets the specified text. 431 * 432 * Deprecated: Please use atk_text_get_string_at_offset() instead. 433 * 434 * Params: 435 * offset = position 436 * boundaryType = An #AtkTextBoundary 437 * startOffset = the starting character offset of the returned string 438 * endOffset = the offset of the first character after the 439 * returned substring 440 * 441 * Returns: a newly allocated string containing the text before @offset bounded 442 * by the specified @boundary_type. Use g_free() to free the returned 443 * string. 444 */ 445 public string getTextBeforeOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset) 446 { 447 auto retStr = atk_text_get_text_before_offset(getTextStruct(), offset, boundaryType, &startOffset, &endOffset); 448 449 scope(exit) Str.freeString(retStr); 450 return Str.toString(retStr); 451 } 452 453 /** 454 * Removes the specified selection. 455 * 456 * Params: 457 * selectionNum = The selection number. The selected regions are 458 * assigned numbers that correspond to how far the region is from the 459 * start of the text. The selected region closest to the beginning 460 * of the text region is assigned the number 0, etc. Note that adding, 461 * moving or deleting a selected region can change the numbering. 462 * 463 * Returns: %TRUE if successful, %FALSE otherwise 464 */ 465 public bool removeSelection(int selectionNum) 466 { 467 return atk_text_remove_selection(getTextStruct(), selectionNum) != 0; 468 } 469 470 /** 471 * Makes a substring of @text visible on the screen by scrolling all necessary parents. 472 * 473 * Params: 474 * startOffset = start offset in the @text 475 * endOffset = end offset in the @text, or -1 for the end of the text. 476 * type = specify where the object should be made visible. 477 * 478 * Returns: whether scrolling was successful. 479 * 480 * Since: 2.32 481 */ 482 public bool scrollSubstringTo(int startOffset, int endOffset, AtkScrollType type) 483 { 484 return atk_text_scroll_substring_to(getTextStruct(), startOffset, endOffset, type) != 0; 485 } 486 487 /** 488 * Move the top-left of a substring of @text to a given position of the screen 489 * by scrolling all necessary parents. 490 * 491 * Params: 492 * startOffset = start offset in the @text 493 * endOffset = end offset in the @text, or -1 for the end of the text. 494 * coords = specify whether coordinates are relative to the screen or to the 495 * parent object. 496 * x = x-position where to scroll to 497 * y = y-position where to scroll to 498 * 499 * Returns: whether scrolling was successful. 500 * 501 * Since: 2.32 502 */ 503 public bool scrollSubstringToPoint(int startOffset, int endOffset, AtkCoordType coords, int x, int y) 504 { 505 return atk_text_scroll_substring_to_point(getTextStruct(), startOffset, endOffset, coords, x, y) != 0; 506 } 507 508 /** 509 * Sets the caret (cursor) position to the specified @offset. 510 * 511 * In the case of rich-text content, this method should either grab focus 512 * or move the sequential focus navigation starting point (if the application 513 * supports this concept) as if the user had clicked on the new caret position. 514 * Typically, this means that the target of this operation is the node containing 515 * the new caret position or one of its ancestors. In other words, after this 516 * method is called, if the user advances focus, it should move to the first 517 * focusable node following the new caret position. 518 * 519 * Calling this method should also scroll the application viewport in a way 520 * that matches the behavior of the application's typical caret motion or tab 521 * navigation as closely as possible. This also means that if the application's 522 * caret motion or focus navigation does not trigger a scroll operation, this 523 * method should not trigger one either. If the application does not have a caret 524 * motion or focus navigation operation, this method should try to scroll the new 525 * caret position into view while minimizing unnecessary scroll motion. 526 * 527 * Params: 528 * offset = the character offset of the new caret position 529 * 530 * Returns: %TRUE if successful, %FALSE otherwise. 531 */ 532 public bool setCaretOffset(int offset) 533 { 534 return atk_text_set_caret_offset(getTextStruct(), offset) != 0; 535 } 536 537 /** 538 * Changes the start and end offset of the specified selection. 539 * 540 * Params: 541 * selectionNum = The selection number. The selected regions are 542 * assigned numbers that correspond to how far the region is from the 543 * start of the text. The selected region closest to the beginning 544 * of the text region is assigned the number 0, etc. Note that adding, 545 * moving or deleting a selected region can change the numbering. 546 * startOffset = the new starting character offset of the selection 547 * endOffset = the new end position of (e.g. offset immediately past) 548 * the selection 549 * 550 * Returns: %TRUE if successful, %FALSE otherwise 551 */ 552 public bool setSelection(int selectionNum, int startOffset, int endOffset) 553 { 554 return atk_text_set_selection(getTextStruct(), selectionNum, startOffset, endOffset) != 0; 555 } 556 557 /** 558 * The "text-attributes-changed" signal is emitted when the text 559 * attributes of the text of an object which implements AtkText 560 * changes. 561 */ 562 gulong addOnTextAttributesChanged(void delegate(TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 563 { 564 return Signals.connect(this, "text-attributes-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 565 } 566 567 /** 568 * The "text-caret-moved" signal is emitted when the caret 569 * position of the text of an object which implements AtkText 570 * changes. 571 * 572 * Params: 573 * arg1 = The new position of the text caret. 574 */ 575 gulong addOnTextCaretMoved(void delegate(int, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 576 { 577 return Signals.connect(this, "text-caret-moved", dlg, connectFlags ^ ConnectFlags.SWAPPED); 578 } 579 580 /** 581 * The "text-changed" signal is emitted when the text of the 582 * object which implements the AtkText interface changes, This 583 * signal will have a detail which is either "insert" or 584 * "delete" which identifies whether the text change was an 585 * insertion or a deletion. 586 * 587 * Deprecated: Use #AtkObject::text-insert or 588 * #AtkObject::text-remove instead. 589 * 590 * Params: 591 * arg1 = The position (character offset) of the insertion or deletion. 592 * arg2 = The length (in characters) of text inserted or deleted. 593 */ 594 gulong addOnTextChanged(void delegate(int, int, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 595 { 596 return Signals.connect(this, "text-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 597 } 598 599 /** 600 * The "text-insert" signal is emitted when a new text is 601 * inserted. If the signal was not triggered by the user 602 * (e.g. typing or pasting text), the "system" detail should be 603 * included. 604 * 605 * Params: 606 * arg1 = The position (character offset) of the insertion. 607 * arg2 = The length (in characters) of text inserted. 608 * arg3 = The new text inserted 609 */ 610 gulong addOnTextInsert(void delegate(int, int, string, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 611 { 612 return Signals.connect(this, "text-insert", dlg, connectFlags ^ ConnectFlags.SWAPPED); 613 } 614 615 /** 616 * The "text-remove" signal is emitted when a new text is 617 * removed. If the signal was not triggered by the user 618 * (e.g. typing or pasting text), the "system" detail should be 619 * included. 620 * 621 * Params: 622 * arg1 = The position (character offset) of the removal. 623 * arg2 = The length (in characters) of text removed. 624 * arg3 = The old text removed 625 */ 626 gulong addOnTextRemove(void delegate(int, int, string, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 627 { 628 return Signals.connect(this, "text-remove", dlg, connectFlags ^ ConnectFlags.SWAPPED); 629 } 630 631 /** 632 * The "text-selection-changed" signal is emitted when the 633 * selected text of an object which implements AtkText changes. 634 */ 635 gulong addOnTextSelectionChanged(void delegate(TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 636 { 637 return Signals.connect(this, "text-selection-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 638 } 639 }