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 glib.Str; 28 public import gobject.Signals; 29 public import gtkc.atk; 30 public import gtkc.atktypes; 31 public import std.algorithm; 32 33 34 /** 35 * #AtkText should be implemented by #AtkObjects on behalf of widgets 36 * that have text content which is either attributed or otherwise 37 * non-trivial. #AtkObjects whose text content is simple, 38 * unattributed, and very brief may expose that content via 39 * #atk_object_get_name instead; however if the text is editable, 40 * multi-line, typically longer than three or four words, attributed, 41 * selectable, or if the object already uses the 'name' ATK property 42 * for other information, the #AtkText interface should be used to 43 * expose the text content. In the case of editable text content, 44 * #AtkEditableText (a subtype of the #AtkText interface) should be 45 * implemented instead. 46 * 47 * #AtkText provides not only traversal facilities and change 48 * notification for text content, but also caret tracking and glyph 49 * bounding box calculations. Note that the text strings are exposed 50 * as UTF-8, and are therefore potentially multi-byte, and 51 * caret-to-byte offset mapping makes no assumptions about the 52 * character length; also bounding box glyph-to-offset mapping may be 53 * complex for languages which use ligatures. 54 */ 55 public template TextT(TStruct) 56 { 57 /** Get the main Gtk struct */ 58 public AtkText* getTextStruct() 59 { 60 return cast(AtkText*)getStruct(); 61 } 62 63 64 /** 65 * Frees the memory associated with an array of AtkTextRange. It is assumed 66 * that the array was returned by the function atk_text_get_bounded_ranges 67 * and is NULL terminated. 68 * 69 * Params: 70 * ranges = A pointer to an array of #AtkTextRange which is 71 * to be freed. 72 * 73 * Since: 1.3 74 */ 75 public static void freeRanges(AtkTextRange*[] ranges) 76 { 77 atk_text_free_ranges(ranges.ptr); 78 } 79 80 /** 81 * Adds a selection bounded by the specified offsets. 82 * 83 * Params: 84 * startOffset = the start position of the selected region 85 * endOffset = the offset of the first character after the selected region. 86 * 87 * Returns: %TRUE if success, %FALSE otherwise 88 */ 89 public bool addSelection(int startOffset, int endOffset) 90 { 91 return atk_text_add_selection(getTextStruct(), startOffset, endOffset) != 0; 92 } 93 94 /** 95 * Get the ranges of text in the specified bounding box. 96 * 97 * Params: 98 * rect = An AtkTextRectangle giving the dimensions of the bounding box. 99 * coordType = Specify whether coordinates are relative to the screen or widget window. 100 * xClipType = Specify the horizontal clip type. 101 * yClipType = Specify the vertical clip type. 102 * 103 * Returns: Array of AtkTextRange. The last 104 * element of the array returned by this function will be NULL. 105 * 106 * Since: 1.3 107 */ 108 public AtkTextRange*[] getBoundedRanges(AtkTextRectangle* rect, AtkCoordType coordType, AtkTextClipType xClipType, AtkTextClipType yClipType) 109 { 110 auto p = atk_text_get_bounded_ranges(getTextStruct(), rect, coordType, xClipType, yClipType); 111 112 return p[0 .. getArrayLength(p)]; 113 } 114 115 /** 116 * Gets the offset position of the caret (cursor). 117 * 118 * Returns: the offset position of the caret (cursor). 119 */ 120 public int getCaretOffset() 121 { 122 return atk_text_get_caret_offset(getTextStruct()); 123 } 124 125 /** 126 * Gets the specified text. 127 * 128 * Params: 129 * offset = position 130 * 131 * Returns: the character at @offset. 132 */ 133 public dchar getCharacterAtOffset(int offset) 134 { 135 return atk_text_get_character_at_offset(getTextStruct(), offset); 136 } 137 138 /** 139 * Gets the character count. 140 * 141 * Returns: the number of characters. 142 */ 143 public int getCharacterCount() 144 { 145 return atk_text_get_character_count(getTextStruct()); 146 } 147 148 /** 149 * Get the bounding box containing the glyph representing the character at 150 * a particular text offset. 151 * 152 * Params: 153 * offset = The offset of the text character for which bounding information is required. 154 * x = Pointer for the x cordinate of the bounding box 155 * y = Pointer for the y cordinate of the bounding box 156 * width = Pointer for the width of the bounding box 157 * height = Pointer for the height of the bounding box 158 * coords = specify whether coordinates are relative to the screen or widget window 159 */ 160 public void getCharacterExtents(int offset, out int x, out int y, out int width, out int height, AtkCoordType coords) 161 { 162 atk_text_get_character_extents(getTextStruct(), offset, &x, &y, &width, &height, coords); 163 } 164 165 /** 166 * Creates an #AtkAttributeSet which consists of the default values of 167 * attributes for the text. See the enum AtkTextAttribute for types of text 168 * attributes that can be returned. Note that other attributes may also be 169 * returned. 170 * 171 * Returns: an #AtkAttributeSet which contains the default 172 * values of attributes. at @offset. this #atkattributeset should be freed by 173 * a call to atk_attribute_set_free(). 174 */ 175 public AtkAttributeSet* getDefaultAttributes() 176 { 177 return atk_text_get_default_attributes(getTextStruct()); 178 } 179 180 /** 181 * Gets the number of selected regions. 182 * 183 * Returns: The number of selected regions, or -1 if a failure 184 * occurred. 185 */ 186 public int getNSelections() 187 { 188 return atk_text_get_n_selections(getTextStruct()); 189 } 190 191 /** 192 * Gets the offset of the character located at coordinates @x and @y. @x and @y 193 * are interpreted as being relative to the screen or this widget's window 194 * depending on @coords. 195 * 196 * Params: 197 * x = screen x-position of character 198 * y = screen y-position of character 199 * coords = specify whether coordinates are relative to the screen or 200 * widget window 201 * 202 * Returns: the offset to the character which is located at 203 * the specified @x and @y coordinates. 204 */ 205 public int getOffsetAtPoint(int x, int y, AtkCoordType coords) 206 { 207 return atk_text_get_offset_at_point(getTextStruct(), x, y, coords); 208 } 209 210 /** 211 * Get the bounding box for text within the specified range. 212 * 213 * Params: 214 * startOffset = The offset of the first text character for which boundary 215 * information is required. 216 * endOffset = The offset of the text character after the last character 217 * for which boundary information is required. 218 * coordType = Specify whether coordinates are relative to the screen or widget window. 219 * rect = A pointer to a AtkTextRectangle which is filled in by this function. 220 * 221 * Since: 1.3 222 */ 223 public void getRangeExtents(int startOffset, int endOffset, AtkCoordType coordType, out AtkTextRectangle rect) 224 { 225 atk_text_get_range_extents(getTextStruct(), startOffset, endOffset, coordType, &rect); 226 } 227 228 /** 229 * Creates an #AtkAttributeSet which consists of the attributes explicitly 230 * set at the position @offset in the text. @start_offset and @end_offset are 231 * set to the start and end of the range around @offset where the attributes are 232 * invariant. Note that @end_offset is the offset of the first character 233 * after the range. See the enum AtkTextAttribute for types of text 234 * attributes that can be returned. Note that other attributes may also be 235 * returned. 236 * 237 * Params: 238 * offset = the offset at which to get the attributes, -1 means the offset of 239 * the character to be inserted at the caret location. 240 * startOffset = the address to put the start offset of the range 241 * endOffset = the address to put the end offset of the range 242 * 243 * Returns: an #AtkAttributeSet which contains the attributes 244 * explicitly set at @offset. This #AtkAttributeSet should be freed by a call 245 * to atk_attribute_set_free(). 246 */ 247 public AtkAttributeSet* getRunAttributes(int offset, out int startOffset, out int endOffset) 248 { 249 return atk_text_get_run_attributes(getTextStruct(), offset, &startOffset, &endOffset); 250 } 251 252 /** 253 * Gets the text from the specified selection. 254 * 255 * Params: 256 * selectionNum = The selection number. The selected regions are 257 * assigned numbers that correspond to how far the region is from the 258 * start of the text. The selected region closest to the beginning 259 * of the text region is assigned the number 0, etc. Note that adding, 260 * moving or deleting a selected region can change the numbering. 261 * startOffset = passes back the start position of the selected region 262 * endOffset = passes back the end position of (e.g. offset immediately past) 263 * the selected region 264 * 265 * Returns: a newly allocated string containing the selected text. Use g_free() 266 * to free the returned string. 267 */ 268 public string getSelection(int selectionNum, out int startOffset, out int endOffset) 269 { 270 auto retStr = atk_text_get_selection(getTextStruct(), selectionNum, &startOffset, &endOffset); 271 272 scope(exit) Str.freeString(retStr); 273 return Str.toString(retStr); 274 } 275 276 /** 277 * Gets a portion of the text exposed through an #AtkText according to a given @offset 278 * and a specific @granularity, along with the start and end offsets defining the 279 * boundaries of such a portion of text. 280 * 281 * If @granularity is ATK_TEXT_GRANULARITY_CHAR the character at the 282 * offset is returned. 283 * 284 * If @granularity is ATK_TEXT_GRANULARITY_WORD the returned string 285 * is from the word start at or before the offset to the word start after 286 * the offset. 287 * 288 * The returned string will contain the word at the offset if the offset 289 * is inside a word and will contain the word before the offset if the 290 * offset is not inside a word. 291 * 292 * If @granularity is ATK_TEXT_GRANULARITY_SENTENCE the returned string 293 * is from the sentence start at or before the offset to the sentence 294 * start after the offset. 295 * 296 * The returned string will contain the sentence at the offset if the offset 297 * is inside a sentence and will contain the sentence before the offset 298 * if the offset is not inside a sentence. 299 * 300 * If @granularity is ATK_TEXT_GRANULARITY_LINE the returned string 301 * is from the line start at or before the offset to the line 302 * start after the offset. 303 * 304 * If @granularity is ATK_TEXT_GRANULARITY_PARAGRAPH the returned string 305 * is from the start of the paragraph at or before the offset to the start 306 * of the following paragraph after the offset. 307 * 308 * Params: 309 * offset = position 310 * granularity = An #AtkTextGranularity 311 * startOffset = the start offset of the returned string, or -1 312 * if an error has occurred (e.g. invalid offset, not implemented) 313 * endOffset = the offset of the first character after the returned string, 314 * or -1 if an error has occurred (e.g. invalid offset, not implemented) 315 * 316 * Returns: a newly allocated string containing the text 317 * at the @offset bounded by the specified @granularity. Use 318 * g_free() to free the returned string. Returns %NULL if the 319 * offset is invalid or no implementation is available. 320 * 321 * Since: 2.10 322 */ 323 public string getStringAtOffset(int offset, AtkTextGranularity granularity, out int startOffset, out int endOffset) 324 { 325 auto retStr = atk_text_get_string_at_offset(getTextStruct(), offset, granularity, &startOffset, &endOffset); 326 327 scope(exit) Str.freeString(retStr); 328 return Str.toString(retStr); 329 } 330 331 /** 332 * Gets the specified text. 333 * 334 * Params: 335 * startOffset = start position 336 * endOffset = end position, or -1 for the end of the string. 337 * 338 * Returns: a newly allocated string containing the text from @start_offset up 339 * to, but not including @end_offset. Use g_free() to free the returned string. 340 */ 341 public string getText(int startOffset, int endOffset) 342 { 343 auto retStr = atk_text_get_text(getTextStruct(), startOffset, endOffset); 344 345 scope(exit) Str.freeString(retStr); 346 return Str.toString(retStr); 347 } 348 349 /** 350 * Gets the specified text. 351 * 352 * Deprecated: Please use atk_text_get_string_at_offset() instead. 353 * 354 * Params: 355 * offset = position 356 * boundaryType = An #AtkTextBoundary 357 * startOffset = the start offset of the returned string 358 * endOffset = the offset of the first character after the 359 * returned substring 360 * 361 * Returns: a newly allocated string containing the text after @offset bounded 362 * by the specified @boundary_type. Use g_free() to free the returned string. 363 */ 364 public string getTextAfterOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset) 365 { 366 auto retStr = atk_text_get_text_after_offset(getTextStruct(), offset, boundaryType, &startOffset, &endOffset); 367 368 scope(exit) Str.freeString(retStr); 369 return Str.toString(retStr); 370 } 371 372 /** 373 * Gets the specified text. 374 * 375 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the 376 * offset is returned. 377 * 378 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string 379 * is from the word start at or before the offset to the word start after 380 * the offset. 381 * 382 * The returned string will contain the word at the offset if the offset 383 * is inside a word and will contain the word before the offset if the 384 * offset is not inside a word. 385 * 386 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned 387 * string is from the sentence start at or before the offset to the sentence 388 * start after the offset. 389 * 390 * The returned string will contain the sentence at the offset if the offset 391 * is inside a sentence and will contain the sentence before the offset 392 * if the offset is not inside a sentence. 393 * 394 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned 395 * string is from the line start at or before the offset to the line 396 * start after the offset. 397 * 398 * Deprecated: This method is deprecated since ATK version 399 * 2.9.4. Please use atk_text_get_string_at_offset() instead. 400 * 401 * Params: 402 * offset = position 403 * boundaryType = An #AtkTextBoundary 404 * startOffset = the start offset of the returned string 405 * endOffset = the offset of the first character after the 406 * returned substring 407 * 408 * Returns: a newly allocated string containing the text at @offset bounded by 409 * the specified @boundary_type. Use g_free() to free the returned string. 410 */ 411 public string getTextAtOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset) 412 { 413 auto retStr = atk_text_get_text_at_offset(getTextStruct(), offset, boundaryType, &startOffset, &endOffset); 414 415 scope(exit) Str.freeString(retStr); 416 return Str.toString(retStr); 417 } 418 419 /** 420 * Gets the specified text. 421 * 422 * Deprecated: Please use atk_text_get_string_at_offset() instead. 423 * 424 * Params: 425 * offset = position 426 * boundaryType = An #AtkTextBoundary 427 * startOffset = the start offset of the returned string 428 * endOffset = the offset of the first character after the 429 * returned substring 430 * 431 * Returns: a newly allocated string containing the text before @offset bounded 432 * by the specified @boundary_type. Use g_free() to free the returned string. 433 */ 434 public string getTextBeforeOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset) 435 { 436 auto retStr = atk_text_get_text_before_offset(getTextStruct(), offset, boundaryType, &startOffset, &endOffset); 437 438 scope(exit) Str.freeString(retStr); 439 return Str.toString(retStr); 440 } 441 442 /** 443 * Removes the specified selection. 444 * 445 * Params: 446 * selectionNum = The selection number. The selected regions are 447 * assigned numbers that correspond to how far the region is from the 448 * start of the text. The selected region closest to the beginning 449 * of the text region is assigned the number 0, etc. Note that adding, 450 * moving or deleting a selected region can change the numbering. 451 * 452 * Returns: %TRUE if success, %FALSE otherwise 453 */ 454 public bool removeSelection(int selectionNum) 455 { 456 return atk_text_remove_selection(getTextStruct(), selectionNum) != 0; 457 } 458 459 /** 460 * Sets the caret (cursor) position to the specified @offset. 461 * 462 * Params: 463 * offset = position 464 * 465 * Returns: %TRUE if success, %FALSE otherwise. 466 */ 467 public bool setCaretOffset(int offset) 468 { 469 return atk_text_set_caret_offset(getTextStruct(), offset) != 0; 470 } 471 472 /** 473 * Changes the start and end offset of the specified selection. 474 * 475 * Params: 476 * selectionNum = The selection number. The selected regions are 477 * assigned numbers that correspond to how far the region is from the 478 * start of the text. The selected region closest to the beginning 479 * of the text region is assigned the number 0, etc. Note that adding, 480 * moving or deleting a selected region can change the numbering. 481 * startOffset = the new start position of the selection 482 * endOffset = the new end position of (e.g. offset immediately past) 483 * the selection 484 * 485 * Returns: %TRUE if success, %FALSE otherwise 486 */ 487 public bool setSelection(int selectionNum, int startOffset, int endOffset) 488 { 489 return atk_text_set_selection(getTextStruct(), selectionNum, startOffset, endOffset) != 0; 490 } 491 492 protected class OnTextAttributesChangedDelegateWrapper 493 { 494 static OnTextAttributesChangedDelegateWrapper[] listeners; 495 void delegate(TextIF) dlg; 496 gulong handlerId; 497 498 this(void delegate(TextIF) dlg) 499 { 500 this.dlg = dlg; 501 this.listeners ~= this; 502 } 503 504 void remove(OnTextAttributesChangedDelegateWrapper source) 505 { 506 foreach(index, wrapper; listeners) 507 { 508 if (wrapper.handlerId == source.handlerId) 509 { 510 listeners[index] = null; 511 listeners = std.algorithm.remove(listeners, index); 512 break; 513 } 514 } 515 } 516 } 517 518 /** 519 * The "text-attributes-changed" signal is emitted when the text 520 * attributes of the text of an object which implements AtkText 521 * changes. 522 */ 523 gulong addOnTextAttributesChanged(void delegate(TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 524 { 525 auto wrapper = new OnTextAttributesChangedDelegateWrapper(dlg); 526 wrapper.handlerId = Signals.connectData( 527 this, 528 "text-attributes-changed", 529 cast(GCallback)&callBackTextAttributesChanged, 530 cast(void*)wrapper, 531 cast(GClosureNotify)&callBackTextAttributesChangedDestroy, 532 connectFlags); 533 return wrapper.handlerId; 534 } 535 536 extern(C) static void callBackTextAttributesChanged(AtkText* textStruct, OnTextAttributesChangedDelegateWrapper wrapper) 537 { 538 wrapper.dlg(wrapper.outer); 539 } 540 541 extern(C) static void callBackTextAttributesChangedDestroy(OnTextAttributesChangedDelegateWrapper wrapper, GClosure* closure) 542 { 543 wrapper.remove(wrapper); 544 } 545 546 protected class OnTextCaretMovedDelegateWrapper 547 { 548 static OnTextCaretMovedDelegateWrapper[] listeners; 549 void delegate(int, TextIF) dlg; 550 gulong handlerId; 551 552 this(void delegate(int, TextIF) dlg) 553 { 554 this.dlg = dlg; 555 this.listeners ~= this; 556 } 557 558 void remove(OnTextCaretMovedDelegateWrapper source) 559 { 560 foreach(index, wrapper; listeners) 561 { 562 if (wrapper.handlerId == source.handlerId) 563 { 564 listeners[index] = null; 565 listeners = std.algorithm.remove(listeners, index); 566 break; 567 } 568 } 569 } 570 } 571 572 /** 573 * The "text-caret-moved" signal is emitted when the caret 574 * position of the text of an object which implements AtkText 575 * changes. 576 * 577 * Params: 578 * arg1 = The new position of the text caret. 579 */ 580 gulong addOnTextCaretMoved(void delegate(int, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 581 { 582 auto wrapper = new OnTextCaretMovedDelegateWrapper(dlg); 583 wrapper.handlerId = Signals.connectData( 584 this, 585 "text-caret-moved", 586 cast(GCallback)&callBackTextCaretMoved, 587 cast(void*)wrapper, 588 cast(GClosureNotify)&callBackTextCaretMovedDestroy, 589 connectFlags); 590 return wrapper.handlerId; 591 } 592 593 extern(C) static void callBackTextCaretMoved(AtkText* textStruct, int arg1, OnTextCaretMovedDelegateWrapper wrapper) 594 { 595 wrapper.dlg(arg1, wrapper.outer); 596 } 597 598 extern(C) static void callBackTextCaretMovedDestroy(OnTextCaretMovedDelegateWrapper wrapper, GClosure* closure) 599 { 600 wrapper.remove(wrapper); 601 } 602 603 protected class OnTextChangedDelegateWrapper 604 { 605 static OnTextChangedDelegateWrapper[] listeners; 606 void delegate(int, int, TextIF) dlg; 607 gulong handlerId; 608 609 this(void delegate(int, int, TextIF) dlg) 610 { 611 this.dlg = dlg; 612 this.listeners ~= this; 613 } 614 615 void remove(OnTextChangedDelegateWrapper source) 616 { 617 foreach(index, wrapper; listeners) 618 { 619 if (wrapper.handlerId == source.handlerId) 620 { 621 listeners[index] = null; 622 listeners = std.algorithm.remove(listeners, index); 623 break; 624 } 625 } 626 } 627 } 628 629 /** 630 * The "text-changed" signal is emitted when the text of the 631 * object which implements the AtkText interface changes, This 632 * signal will have a detail which is either "insert" or 633 * "delete" which identifies whether the text change was an 634 * insertion or a deletion. 635 * 636 * Deprecated: Use #AtkObject::text-insert or 637 * #AtkObject::text-remove instead. 638 * 639 * Params: 640 * arg1 = The position (character offset) of the insertion or deletion. 641 * arg2 = The length (in characters) of text inserted or deleted. 642 */ 643 gulong addOnTextChanged(void delegate(int, int, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 644 { 645 auto wrapper = new OnTextChangedDelegateWrapper(dlg); 646 wrapper.handlerId = Signals.connectData( 647 this, 648 "text-changed", 649 cast(GCallback)&callBackTextChanged, 650 cast(void*)wrapper, 651 cast(GClosureNotify)&callBackTextChangedDestroy, 652 connectFlags); 653 return wrapper.handlerId; 654 } 655 656 extern(C) static void callBackTextChanged(AtkText* textStruct, int arg1, int arg2, OnTextChangedDelegateWrapper wrapper) 657 { 658 wrapper.dlg(arg1, arg2, wrapper.outer); 659 } 660 661 extern(C) static void callBackTextChangedDestroy(OnTextChangedDelegateWrapper wrapper, GClosure* closure) 662 { 663 wrapper.remove(wrapper); 664 } 665 666 protected class OnTextInsertDelegateWrapper 667 { 668 static OnTextInsertDelegateWrapper[] listeners; 669 void delegate(int, int, string, TextIF) dlg; 670 gulong handlerId; 671 672 this(void delegate(int, int, string, TextIF) dlg) 673 { 674 this.dlg = dlg; 675 this.listeners ~= this; 676 } 677 678 void remove(OnTextInsertDelegateWrapper source) 679 { 680 foreach(index, wrapper; listeners) 681 { 682 if (wrapper.handlerId == source.handlerId) 683 { 684 listeners[index] = null; 685 listeners = std.algorithm.remove(listeners, index); 686 break; 687 } 688 } 689 } 690 } 691 692 /** 693 * The "text-insert" signal is emitted when a new text is 694 * inserted. If the signal was not triggered by the user 695 * (e.g. typing or pasting text), the "system" detail should be 696 * included. 697 * 698 * Params: 699 * arg1 = The position (character offset) of the insertion. 700 * arg2 = The length (in characters) of text inserted. 701 * arg3 = The new text inserted 702 */ 703 gulong addOnTextInsert(void delegate(int, int, string, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 704 { 705 auto wrapper = new OnTextInsertDelegateWrapper(dlg); 706 wrapper.handlerId = Signals.connectData( 707 this, 708 "text-insert", 709 cast(GCallback)&callBackTextInsert, 710 cast(void*)wrapper, 711 cast(GClosureNotify)&callBackTextInsertDestroy, 712 connectFlags); 713 return wrapper.handlerId; 714 } 715 716 extern(C) static void callBackTextInsert(AtkText* textStruct, int arg1, int arg2, char* arg3, OnTextInsertDelegateWrapper wrapper) 717 { 718 wrapper.dlg(arg1, arg2, Str.toString(arg3), wrapper.outer); 719 } 720 721 extern(C) static void callBackTextInsertDestroy(OnTextInsertDelegateWrapper wrapper, GClosure* closure) 722 { 723 wrapper.remove(wrapper); 724 } 725 726 protected class OnTextRemoveDelegateWrapper 727 { 728 static OnTextRemoveDelegateWrapper[] listeners; 729 void delegate(int, int, string, TextIF) dlg; 730 gulong handlerId; 731 732 this(void delegate(int, int, string, TextIF) dlg) 733 { 734 this.dlg = dlg; 735 this.listeners ~= this; 736 } 737 738 void remove(OnTextRemoveDelegateWrapper source) 739 { 740 foreach(index, wrapper; listeners) 741 { 742 if (wrapper.handlerId == source.handlerId) 743 { 744 listeners[index] = null; 745 listeners = std.algorithm.remove(listeners, index); 746 break; 747 } 748 } 749 } 750 } 751 752 /** 753 * The "text-remove" signal is emitted when a new text is 754 * removed. If the signal was not triggered by the user 755 * (e.g. typing or pasting text), the "system" detail should be 756 * included. 757 * 758 * Params: 759 * arg1 = The position (character offset) of the removal. 760 * arg2 = The length (in characters) of text removed. 761 * arg3 = The old text removed 762 */ 763 gulong addOnTextRemove(void delegate(int, int, string, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 764 { 765 auto wrapper = new OnTextRemoveDelegateWrapper(dlg); 766 wrapper.handlerId = Signals.connectData( 767 this, 768 "text-remove", 769 cast(GCallback)&callBackTextRemove, 770 cast(void*)wrapper, 771 cast(GClosureNotify)&callBackTextRemoveDestroy, 772 connectFlags); 773 return wrapper.handlerId; 774 } 775 776 extern(C) static void callBackTextRemove(AtkText* textStruct, int arg1, int arg2, char* arg3, OnTextRemoveDelegateWrapper wrapper) 777 { 778 wrapper.dlg(arg1, arg2, Str.toString(arg3), wrapper.outer); 779 } 780 781 extern(C) static void callBackTextRemoveDestroy(OnTextRemoveDelegateWrapper wrapper, GClosure* closure) 782 { 783 wrapper.remove(wrapper); 784 } 785 786 protected class OnTextSelectionChangedDelegateWrapper 787 { 788 static OnTextSelectionChangedDelegateWrapper[] listeners; 789 void delegate(TextIF) dlg; 790 gulong handlerId; 791 792 this(void delegate(TextIF) dlg) 793 { 794 this.dlg = dlg; 795 this.listeners ~= this; 796 } 797 798 void remove(OnTextSelectionChangedDelegateWrapper source) 799 { 800 foreach(index, wrapper; listeners) 801 { 802 if (wrapper.handlerId == source.handlerId) 803 { 804 listeners[index] = null; 805 listeners = std.algorithm.remove(listeners, index); 806 break; 807 } 808 } 809 } 810 } 811 812 /** 813 * The "text-selection-changed" signal is emitted when the 814 * selected text of an object which implements AtkText changes. 815 */ 816 gulong addOnTextSelectionChanged(void delegate(TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 817 { 818 auto wrapper = new OnTextSelectionChangedDelegateWrapper(dlg); 819 wrapper.handlerId = Signals.connectData( 820 this, 821 "text-selection-changed", 822 cast(GCallback)&callBackTextSelectionChanged, 823 cast(void*)wrapper, 824 cast(GClosureNotify)&callBackTextSelectionChangedDestroy, 825 connectFlags); 826 return wrapper.handlerId; 827 } 828 829 extern(C) static void callBackTextSelectionChanged(AtkText* textStruct, OnTextSelectionChangedDelegateWrapper wrapper) 830 { 831 wrapper.dlg(wrapper.outer); 832 } 833 834 extern(C) static void callBackTextSelectionChangedDestroy(OnTextSelectionChangedDelegateWrapper wrapper, GClosure* closure) 835 { 836 wrapper.remove(wrapper); 837 } 838 839 /** 840 * Frees the memory used by an #AtkAttributeSet, including all its 841 * #AtkAttributes. 842 * 843 * Params: 844 * attribSet = The #AtkAttributeSet to free 845 */ 846 public static void attributeSetFree(AtkAttributeSet* attribSet) 847 { 848 atk_attribute_set_free(attribSet); 849 } 850 851 /** 852 * Get the #AtkTextAttribute type corresponding to a text attribute name. 853 * 854 * Params: 855 * name = a string which is the (non-localized) name of an ATK text attribute. 856 * 857 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified 858 * name, 859 * or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found. 860 */ 861 public static AtkTextAttribute attributeForName(string name) 862 { 863 return atk_text_attribute_for_name(Str.toStringz(name)); 864 } 865 866 /** 867 * Gets the name corresponding to the #AtkTextAttribute 868 * 869 * Params: 870 * attr = The #AtkTextAttribute whose name is required 871 * 872 * Returns: a string containing the name; this string should not be freed 873 */ 874 public static string attributeGetName(AtkTextAttribute attr) 875 { 876 return Str.toString(atk_text_attribute_get_name(attr)); 877 } 878 879 /** 880 * Gets the value for the index of the #AtkTextAttribute 881 * 882 * Params: 883 * attr = The #AtkTextAttribute for which a value is required 884 * index = The index of the required value 885 * 886 * Returns: a string containing the value; this string 887 * should not be freed; %NULL is returned if there are no values 888 * maintained for the attr value. 889 */ 890 public static string attributeGetValue(AtkTextAttribute attr, int index) 891 { 892 return Str.toString(atk_text_attribute_get_value(attr, index)); 893 } 894 895 /** 896 * Associate @name with a new #AtkTextAttribute 897 * 898 * Params: 899 * name = a name string 900 * 901 * Returns: an #AtkTextAttribute associated with @name 902 */ 903 public static AtkTextAttribute attributeRegister(string name) 904 { 905 return atk_text_attribute_register(Str.toStringz(name)); 906 } 907 }