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