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 gobject.ObjectG; 32 public import gobject.Signals; 33 public import gtkc.atktypes; 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 * Get the bounding box containing the glyph representing the character at 152 * a particular text offset. 153 * 154 * Params: 155 * offset = The offset of the text character for which bounding information is required. 156 * x = Pointer for the x coordinate of the bounding box 157 * y = Pointer for the y coordinate of the bounding box 158 * width = Pointer for the width of the bounding box 159 * height = Pointer for the height of the bounding box 160 * coords = specify whether coordinates are relative to the screen or widget window 161 */ 162 public void getCharacterExtents(int offset, out int x, out int y, out int width, out int height, AtkCoordType coords) 163 { 164 atk_text_get_character_extents(getTextStruct(), offset, &x, &y, &width, &height, coords); 165 } 166 167 /** 168 * Creates an #AtkAttributeSet which consists of the default values of 169 * attributes for the text. See the enum AtkTextAttribute for types of text 170 * attributes that can be returned. Note that other attributes may also be 171 * returned. 172 * 173 * Returns: an #AtkAttributeSet which contains the default text 174 * attributes for this #AtkText. This #AtkAttributeSet should be freed by 175 * a call to atk_attribute_set_free(). 176 */ 177 public AtkAttributeSet* getDefaultAttributes() 178 { 179 return atk_text_get_default_attributes(getTextStruct()); 180 } 181 182 /** 183 * Gets the number of selected regions. 184 * 185 * Returns: The number of selected regions, or -1 in the case of failure. 186 */ 187 public int getNSelections() 188 { 189 return atk_text_get_n_selections(getTextStruct()); 190 } 191 192 /** 193 * Gets the offset of the character located at coordinates @x and @y. @x and @y 194 * are interpreted as being relative to the screen or this widget's window 195 * depending on @coords. 196 * 197 * Params: 198 * x = screen x-position of character 199 * y = screen y-position of character 200 * coords = specify whether coordinates are relative to the screen or 201 * widget window 202 * 203 * Returns: the offset to the character which is located at the specified 204 * @x and @y coordinates of -1 in case of failure. 205 */ 206 public int getOffsetAtPoint(int x, int y, AtkCoordType coords) 207 { 208 return atk_text_get_offset_at_point(getTextStruct(), x, y, coords); 209 } 210 211 /** 212 * Get the bounding box for text within the specified range. 213 * 214 * Params: 215 * startOffset = The offset of the first text character for which boundary 216 * information is required. 217 * endOffset = The offset of the text character after the last character 218 * for which boundary information is required. 219 * coordType = Specify whether coordinates are relative to the screen or widget window. 220 * rect = A pointer to a AtkTextRectangle which is filled in by this function. 221 * 222 * Since: 1.3 223 */ 224 public void getRangeExtents(int startOffset, int endOffset, AtkCoordType coordType, out AtkTextRectangle rect) 225 { 226 atk_text_get_range_extents(getTextStruct(), startOffset, endOffset, coordType, &rect); 227 } 228 229 /** 230 * Creates an #AtkAttributeSet which consists of the attributes explicitly 231 * set at the position @offset in the text. @start_offset and @end_offset are 232 * set to the start and end of the range around @offset where the attributes are 233 * invariant. Note that @end_offset is the offset of the first character 234 * after the range. See the enum AtkTextAttribute for types of text 235 * attributes that can be returned. Note that other attributes may also be 236 * returned. 237 * 238 * Params: 239 * offset = the character offset at which to get the attributes, -1 means the offset of 240 * the character to be inserted at the caret location. 241 * startOffset = the address to put the start offset of the range 242 * endOffset = the address to put the end offset of the range 243 * 244 * Returns: an #AtkAttributeSet which contains the attributes 245 * explicitly set at @offset. This #AtkAttributeSet should be freed by 246 * a call to atk_attribute_set_free(). 247 */ 248 public AtkAttributeSet* getRunAttributes(int offset, out int startOffset, out int endOffset) 249 { 250 return atk_text_get_run_attributes(getTextStruct(), offset, &startOffset, &endOffset); 251 } 252 253 /** 254 * Gets the text from the specified selection. 255 * 256 * Params: 257 * selectionNum = The selection number. The selected regions are 258 * assigned numbers that correspond to how far the region is from the 259 * start of the text. The selected region closest to the beginning 260 * of the text region is assigned the number 0, etc. Note that adding, 261 * moving or deleting a selected region can change the numbering. 262 * startOffset = passes back the starting character offset of the selected region 263 * endOffset = passes back the ending character offset (offset immediately past) 264 * of the selected region 265 * 266 * Returns: a newly allocated string containing the selected text. Use g_free() 267 * to free the returned string. 268 */ 269 public string getSelection(int selectionNum, out int startOffset, out int endOffset) 270 { 271 auto retStr = atk_text_get_selection(getTextStruct(), selectionNum, &startOffset, &endOffset); 272 273 scope(exit) Str.freeString(retStr); 274 return Str.toString(retStr); 275 } 276 277 /** 278 * Gets a portion of the text exposed through an #AtkText according to a given @offset 279 * and a specific @granularity, along with the start and end offsets defining the 280 * boundaries of such a portion of text. 281 * 282 * If @granularity is ATK_TEXT_GRANULARITY_CHAR the character at the 283 * offset is returned. 284 * 285 * If @granularity is ATK_TEXT_GRANULARITY_WORD the returned string 286 * is from the word start at or before the offset to the word start after 287 * the offset. 288 * 289 * The returned string will contain the word at the offset if the offset 290 * is inside a word and will contain the word before the offset if the 291 * offset is not inside a word. 292 * 293 * If @granularity is ATK_TEXT_GRANULARITY_SENTENCE the returned string 294 * is from the sentence start at or before the offset to the sentence 295 * start after the offset. 296 * 297 * The returned string will contain the sentence at the offset if the offset 298 * is inside a sentence and will contain the sentence before the offset 299 * if the offset is not inside a sentence. 300 * 301 * If @granularity is ATK_TEXT_GRANULARITY_LINE the returned string 302 * is from the line start at or before the offset to the line 303 * start after the offset. 304 * 305 * If @granularity is ATK_TEXT_GRANULARITY_PARAGRAPH the returned string 306 * is from the start of the paragraph at or before the offset to the start 307 * of the following paragraph after the offset. 308 * 309 * Params: 310 * offset = position 311 * granularity = An #AtkTextGranularity 312 * startOffset = the starting character offset of the returned string, or -1 313 * in the case of error (e.g. invalid offset, not implemented) 314 * endOffset = the offset of the first character after the returned string, 315 * or -1 in the case of error (e.g. invalid offset, not implemented) 316 * 317 * Returns: a newly allocated string containing the text at 318 * the @offset bounded by the specified @granularity. Use g_free() 319 * to free the returned string. Returns %NULL if the offset is invalid 320 * or no implementation is available. 321 * 322 * Since: 2.10 323 */ 324 public string getStringAtOffset(int offset, AtkTextGranularity granularity, out int startOffset, out int endOffset) 325 { 326 auto retStr = atk_text_get_string_at_offset(getTextStruct(), offset, granularity, &startOffset, &endOffset); 327 328 scope(exit) Str.freeString(retStr); 329 return Str.toString(retStr); 330 } 331 332 /** 333 * Gets the specified text. 334 * 335 * Params: 336 * startOffset = a starting character offset within @text 337 * endOffset = an ending character offset within @text, or -1 for the end of the string. 338 * 339 * Returns: a newly allocated string containing the text from @start_offset up 340 * to, but not including @end_offset. Use g_free() to free the returned 341 * string. 342 */ 343 public string getText(int startOffset, int endOffset) 344 { 345 auto retStr = atk_text_get_text(getTextStruct(), startOffset, endOffset); 346 347 scope(exit) Str.freeString(retStr); 348 return Str.toString(retStr); 349 } 350 351 /** 352 * Gets the specified text. 353 * 354 * Deprecated: Please use atk_text_get_string_at_offset() instead. 355 * 356 * Params: 357 * offset = position 358 * boundaryType = An #AtkTextBoundary 359 * startOffset = the starting character offset of the returned string 360 * endOffset = the offset of the first character after the 361 * returned substring 362 * 363 * Returns: a newly allocated string containing the text after @offset bounded 364 * by the specified @boundary_type. Use g_free() to free the returned 365 * string. 366 */ 367 public string getTextAfterOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset) 368 { 369 auto retStr = atk_text_get_text_after_offset(getTextStruct(), offset, boundaryType, &startOffset, &endOffset); 370 371 scope(exit) Str.freeString(retStr); 372 return Str.toString(retStr); 373 } 374 375 /** 376 * Gets the specified text. 377 * 378 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the 379 * offset is returned. 380 * 381 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string 382 * is from the word start at or before the offset to the word start after 383 * the offset. 384 * 385 * The returned string will contain the word at the offset if the offset 386 * is inside a word and will contain the word before the offset if the 387 * offset is not inside a word. 388 * 389 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned 390 * string is from the sentence start at or before the offset to the sentence 391 * start after the offset. 392 * 393 * The returned string will contain the sentence at the offset if the offset 394 * is inside a sentence and will contain the sentence before the offset 395 * if the offset is not inside a sentence. 396 * 397 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned 398 * string is from the line start at or before the offset to the line 399 * start after the offset. 400 * 401 * Deprecated: This method is deprecated since ATK version 402 * 2.9.4. Please use atk_text_get_string_at_offset() instead. 403 * 404 * Params: 405 * offset = position 406 * boundaryType = An #AtkTextBoundary 407 * startOffset = the starting character offset of the returned string 408 * endOffset = the offset of the first character after the 409 * returned substring 410 * 411 * Returns: a newly allocated string containing the text at @offset bounded 412 * by the specified @boundary_type. Use g_free() to free the returned 413 * string. 414 */ 415 public string getTextAtOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset) 416 { 417 auto retStr = atk_text_get_text_at_offset(getTextStruct(), offset, boundaryType, &startOffset, &endOffset); 418 419 scope(exit) Str.freeString(retStr); 420 return Str.toString(retStr); 421 } 422 423 /** 424 * Gets the specified text. 425 * 426 * Deprecated: Please use atk_text_get_string_at_offset() instead. 427 * 428 * Params: 429 * offset = position 430 * boundaryType = An #AtkTextBoundary 431 * startOffset = the starting character offset of the returned string 432 * endOffset = the offset of the first character after the 433 * returned substring 434 * 435 * Returns: a newly allocated string containing the text before @offset bounded 436 * by the specified @boundary_type. Use g_free() to free the returned 437 * string. 438 */ 439 public string getTextBeforeOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset) 440 { 441 auto retStr = atk_text_get_text_before_offset(getTextStruct(), offset, boundaryType, &startOffset, &endOffset); 442 443 scope(exit) Str.freeString(retStr); 444 return Str.toString(retStr); 445 } 446 447 /** 448 * Removes the specified selection. 449 * 450 * Params: 451 * selectionNum = The selection number. The selected regions are 452 * assigned numbers that correspond to how far the region is from the 453 * start of the text. The selected region closest to the beginning 454 * of the text region is assigned the number 0, etc. Note that adding, 455 * moving or deleting a selected region can change the numbering. 456 * 457 * Returns: %TRUE if successful, %FALSE otherwise 458 */ 459 public bool removeSelection(int selectionNum) 460 { 461 return atk_text_remove_selection(getTextStruct(), selectionNum) != 0; 462 } 463 464 /** 465 * Makes @text visible on the screen by scrolling all necessary parents. 466 * 467 * Contrary to atk_text_set_position, this does not actually move 468 * @text in its parent, this only makes the parents scroll so that the 469 * object shows up on the screen, given its current position within the parents. 470 * 471 * Params: 472 * startOffset = start position 473 * endOffset = end position, or -1 for the end of the string. 474 * type = specify where the object should be made visible. 475 * 476 * Returns: whether scrolling was successful. 477 * 478 * Since: 2.32 479 */ 480 public bool scrollSubstringTo(int startOffset, int endOffset, AtkScrollType type) 481 { 482 return atk_text_scroll_substring_to(getTextStruct(), startOffset, endOffset, type) != 0; 483 } 484 485 /** 486 * Makes an object visible on the screen at a given position by scrolling all 487 * necessary parents. 488 * 489 * Params: 490 * startOffset = start position 491 * endOffset = end position, or -1 for the end of the string. 492 * coords = specify whether coordinates are relative to the screen or to the 493 * parent object. 494 * x = x-position where to scroll to 495 * y = y-position where to scroll to 496 * 497 * Returns: whether scrolling was successful. 498 * 499 * Since: 2.32 500 */ 501 public bool scrollSubstringToPoint(int startOffset, int endOffset, AtkCoordType coords, int x, int y) 502 { 503 return atk_text_scroll_substring_to_point(getTextStruct(), startOffset, endOffset, coords, x, y) != 0; 504 } 505 506 /** 507 * Sets the caret (cursor) position to the specified @offset. 508 * 509 * Params: 510 * offset = the character offset of the new caret position 511 * 512 * Returns: %TRUE if successful, %FALSE otherwise. 513 */ 514 public bool setCaretOffset(int offset) 515 { 516 return atk_text_set_caret_offset(getTextStruct(), offset) != 0; 517 } 518 519 /** 520 * Changes the start and end offset of the specified selection. 521 * 522 * Params: 523 * selectionNum = The selection number. The selected regions are 524 * assigned numbers that correspond to how far the region is from the 525 * start of the text. The selected region closest to the beginning 526 * of the text region is assigned the number 0, etc. Note that adding, 527 * moving or deleting a selected region can change the numbering. 528 * startOffset = the new starting character offset of the selection 529 * endOffset = the new end position of (e.g. offset immediately past) 530 * the selection 531 * 532 * Returns: %TRUE if successful, %FALSE otherwise 533 */ 534 public bool setSelection(int selectionNum, int startOffset, int endOffset) 535 { 536 return atk_text_set_selection(getTextStruct(), selectionNum, startOffset, endOffset) != 0; 537 } 538 539 /** 540 * The "text-attributes-changed" signal is emitted when the text 541 * attributes of the text of an object which implements AtkText 542 * changes. 543 */ 544 gulong addOnTextAttributesChanged(void delegate(TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 545 { 546 return Signals.connect(this, "text-attributes-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 547 } 548 549 /** 550 * The "text-caret-moved" signal is emitted when the caret 551 * position of the text of an object which implements AtkText 552 * changes. 553 * 554 * Params: 555 * arg1 = The new position of the text caret. 556 */ 557 gulong addOnTextCaretMoved(void delegate(int, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 558 { 559 return Signals.connect(this, "text-caret-moved", dlg, connectFlags ^ ConnectFlags.SWAPPED); 560 } 561 562 /** 563 * The "text-changed" signal is emitted when the text of the 564 * object which implements the AtkText interface changes, This 565 * signal will have a detail which is either "insert" or 566 * "delete" which identifies whether the text change was an 567 * insertion or a deletion. 568 * 569 * Deprecated: Use #AtkObject::text-insert or 570 * #AtkObject::text-remove instead. 571 * 572 * Params: 573 * arg1 = The position (character offset) of the insertion or deletion. 574 * arg2 = The length (in characters) of text inserted or deleted. 575 */ 576 gulong addOnTextChanged(void delegate(int, int, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 577 { 578 return Signals.connect(this, "text-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 579 } 580 581 /** 582 * The "text-insert" signal is emitted when a new text is 583 * inserted. If the signal was not triggered by the user 584 * (e.g. typing or pasting text), the "system" detail should be 585 * included. 586 * 587 * Params: 588 * arg1 = The position (character offset) of the insertion. 589 * arg2 = The length (in characters) of text inserted. 590 * arg3 = The new text inserted 591 */ 592 gulong addOnTextInsert(void delegate(int, int, string, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 593 { 594 return Signals.connect(this, "text-insert", dlg, connectFlags ^ ConnectFlags.SWAPPED); 595 } 596 597 /** 598 * The "text-remove" signal is emitted when a new text is 599 * removed. If the signal was not triggered by the user 600 * (e.g. typing or pasting text), the "system" detail should be 601 * included. 602 * 603 * Params: 604 * arg1 = The position (character offset) of the removal. 605 * arg2 = The length (in characters) of text removed. 606 * arg3 = The old text removed 607 */ 608 gulong addOnTextRemove(void delegate(int, int, string, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 609 { 610 return Signals.connect(this, "text-remove", dlg, connectFlags ^ ConnectFlags.SWAPPED); 611 } 612 613 /** 614 * The "text-selection-changed" signal is emitted when the 615 * selected text of an object which implements AtkText changes. 616 */ 617 gulong addOnTextSelectionChanged(void delegate(TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 618 { 619 return Signals.connect(this, "text-selection-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 620 } 621 }