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.TextIF; 26 27 private import atk.TextRange; 28 private import atk.c.functions; 29 public import atk.c.types; 30 private import glib.Str; 31 private import glib.c.functions; 32 private import gobject.ObjectG; 33 private import gobject.Signals; 34 private 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 interface TextIF{ 59 /** Get the main Gtk struct */ 60 public AtkText* getTextStruct(bool transferOwnership = false); 61 62 /** the main Gtk struct as a void* */ 63 protected void* getStruct(); 64 65 66 /** */ 67 public static GType getType() 68 { 69 return atk_text_get_type(); 70 } 71 72 /** 73 * Frees the memory associated with an array of AtkTextRange. It is assumed 74 * that the array was returned by the function atk_text_get_bounded_ranges 75 * and is NULL terminated. 76 * 77 * Params: 78 * ranges = A pointer to an array of #AtkTextRange which is 79 * to be freed. 80 * 81 * Since: 1.3 82 */ 83 public static void freeRanges(TextRange[] ranges) 84 { 85 AtkTextRange*[] rangesArray = new AtkTextRange*[ranges.length]; 86 for ( int i = 0; i < ranges.length; i++ ) 87 { 88 rangesArray[i] = ranges[i].getTextRangeStruct(); 89 } 90 91 atk_text_free_ranges(rangesArray.ptr); 92 } 93 94 /** 95 * Adds a selection bounded by the specified offsets. 96 * 97 * Params: 98 * startOffset = the starting character offset of the selected region 99 * endOffset = the offset of the first character after the selected region. 100 * 101 * Returns: %TRUE if successful, %FALSE otherwise 102 */ 103 public bool addSelection(int startOffset, int endOffset); 104 105 /** 106 * Get the ranges of text in the specified bounding box. 107 * 108 * Params: 109 * rect = An AtkTextRectangle giving the dimensions of the bounding box. 110 * coordType = Specify whether coordinates are relative to the screen or widget window. 111 * xClipType = Specify the horizontal clip type. 112 * yClipType = Specify the vertical clip type. 113 * 114 * Returns: Array of AtkTextRange. The last 115 * element of the array returned by this function will be NULL. 116 * 117 * Since: 1.3 118 */ 119 public TextRange[] getBoundedRanges(AtkTextRectangle* rect, AtkCoordType coordType, AtkTextClipType xClipType, AtkTextClipType yClipType); 120 121 /** 122 * Gets the offset of the position of the caret (cursor). 123 * 124 * Returns: the character offset of the position of the caret or -1 if 125 * the caret is not located inside the element or in the case of 126 * any other failure. 127 */ 128 public int getCaretOffset(); 129 130 /** 131 * Gets the specified text. 132 * 133 * Params: 134 * offset = a character offset within @text 135 * 136 * Returns: the character at @offset or 0 in the case of failure. 137 */ 138 public dchar getCharacterAtOffset(int offset); 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 /** 148 * If the extent can not be obtained (e.g. missing support), all of x, y, width, 149 * height are set to -1. 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 /** 165 * Creates an #AtkAttributeSet which consists of the default values of 166 * attributes for the text. See the enum AtkTextAttribute for types of text 167 * attributes that can be returned. Note that other attributes may also be 168 * returned. 169 * 170 * Returns: an #AtkAttributeSet which contains the default text 171 * attributes for this #AtkText. This #AtkAttributeSet should be freed by 172 * a call to atk_attribute_set_free(). 173 */ 174 public AtkAttributeSet* getDefaultAttributes(); 175 176 /** 177 * Gets the number of selected regions. 178 * 179 * Returns: The number of selected regions, or -1 in the case of failure. 180 */ 181 public int getNSelections(); 182 183 /** 184 * Gets the offset of the character located at coordinates @x and @y. @x and @y 185 * are interpreted as being relative to the screen or this widget's window 186 * depending on @coords. 187 * 188 * Params: 189 * x = screen x-position of character 190 * y = screen y-position of character 191 * coords = specify whether coordinates are relative to the screen or 192 * widget window 193 * 194 * Returns: the offset to the character which is located at the specified 195 * @x and @y coordinates of -1 in case of failure. 196 */ 197 public int getOffsetAtPoint(int x, int y, AtkCoordType coords); 198 199 /** 200 * Get the bounding box for text within the specified range. 201 * 202 * If the extents can not be obtained (e.g. or missing support), the rectangle 203 * fields are set to -1. 204 * 205 * Params: 206 * startOffset = The offset of the first text character for which boundary 207 * information is required. 208 * endOffset = The offset of the text character after the last character 209 * for which boundary information is required. 210 * coordType = Specify whether coordinates are relative to the screen or widget window. 211 * rect = A pointer to a AtkTextRectangle which is filled in by this function. 212 * 213 * Since: 1.3 214 */ 215 public void getRangeExtents(int startOffset, int endOffset, AtkCoordType coordType, out AtkTextRectangle rect); 216 217 /** 218 * Creates an #AtkAttributeSet which consists of the attributes explicitly 219 * set at the position @offset in the text. @start_offset and @end_offset are 220 * set to the start and end of the range around @offset where the attributes are 221 * invariant. Note that @end_offset is the offset of the first character 222 * after the range. See the enum AtkTextAttribute for types of text 223 * attributes that can be returned. Note that other attributes may also be 224 * returned. 225 * 226 * Params: 227 * offset = the character offset at which to get the attributes, -1 means the offset of 228 * the character to be inserted at the caret location. 229 * startOffset = the address to put the start offset of the range 230 * endOffset = the address to put the end offset of the range 231 * 232 * Returns: an #AtkAttributeSet which contains the attributes 233 * explicitly set at @offset. This #AtkAttributeSet should be freed by 234 * a call to atk_attribute_set_free(). 235 */ 236 public AtkAttributeSet* getRunAttributes(int offset, out int startOffset, out int endOffset); 237 238 /** 239 * Gets the text from the specified selection. 240 * 241 * Params: 242 * selectionNum = The selection number. The selected regions are 243 * assigned numbers that correspond to how far the region is from the 244 * start of the text. The selected region closest to the beginning 245 * of the text region is assigned the number 0, etc. Note that adding, 246 * moving or deleting a selected region can change the numbering. 247 * startOffset = passes back the starting character offset of the selected region 248 * endOffset = passes back the ending character offset (offset immediately past) 249 * of the selected region 250 * 251 * Returns: a newly allocated string containing the selected text. Use g_free() 252 * to free the returned string. 253 */ 254 public string getSelection(int selectionNum, out int startOffset, out int endOffset); 255 256 /** 257 * Gets a portion of the text exposed through an #AtkText according to a given @offset 258 * and a specific @granularity, along with the start and end offsets defining the 259 * boundaries of such a portion of text. 260 * 261 * If @granularity is ATK_TEXT_GRANULARITY_CHAR the character at the 262 * offset is returned. 263 * 264 * If @granularity is ATK_TEXT_GRANULARITY_WORD the returned string 265 * is from the word start at or before the offset to the word start after 266 * the offset. 267 * 268 * The returned string will contain the word at the offset if the offset 269 * is inside a word and will contain the word before the offset if the 270 * offset is not inside a word. 271 * 272 * If @granularity is ATK_TEXT_GRANULARITY_SENTENCE the returned string 273 * is from the sentence start at or before the offset to the sentence 274 * start after the offset. 275 * 276 * The returned string will contain the sentence at the offset if the offset 277 * is inside a sentence and will contain the sentence before the offset 278 * if the offset is not inside a sentence. 279 * 280 * If @granularity is ATK_TEXT_GRANULARITY_LINE the returned string 281 * is from the line start at or before the offset to the line 282 * start after the offset. 283 * 284 * If @granularity is ATK_TEXT_GRANULARITY_PARAGRAPH the returned string 285 * is from the start of the paragraph at or before the offset to the start 286 * of the following paragraph after the offset. 287 * 288 * Params: 289 * offset = position 290 * granularity = An #AtkTextGranularity 291 * startOffset = the starting character offset of the returned string, or -1 292 * in the case of error (e.g. invalid offset, not implemented) 293 * endOffset = the offset of the first character after the returned string, 294 * or -1 in the case of error (e.g. invalid offset, not implemented) 295 * 296 * Returns: a newly allocated string containing the text at 297 * the @offset bounded by the specified @granularity. Use g_free() 298 * to free the returned string. Returns %NULL if the offset is invalid 299 * or no implementation is available. 300 * 301 * Since: 2.10 302 */ 303 public string getStringAtOffset(int offset, AtkTextGranularity granularity, out int startOffset, out int endOffset); 304 305 /** 306 * Gets the specified text. 307 * 308 * Params: 309 * startOffset = a starting character offset within @text 310 * endOffset = an ending character offset within @text, or -1 for the end of the string. 311 * 312 * Returns: a newly allocated string containing the text from @start_offset up 313 * to, but not including @end_offset. Use g_free() to free the returned 314 * string. 315 */ 316 public string getText(int startOffset, int endOffset); 317 318 /** 319 * Gets the specified text. 320 * 321 * Deprecated: Please use atk_text_get_string_at_offset() instead. 322 * 323 * Params: 324 * offset = position 325 * boundaryType = An #AtkTextBoundary 326 * startOffset = the starting character offset of the returned string 327 * endOffset = the offset of the first character after the 328 * returned substring 329 * 330 * Returns: a newly allocated string containing the text after @offset bounded 331 * by the specified @boundary_type. Use g_free() to free the returned 332 * string. 333 */ 334 public string getTextAfterOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset); 335 336 /** 337 * Gets the specified text. 338 * 339 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the 340 * offset is returned. 341 * 342 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string 343 * is from the word start at or before the offset to the word start after 344 * the offset. 345 * 346 * The returned string will contain the word at the offset if the offset 347 * is inside a word and will contain the word before the offset if the 348 * offset is not inside a word. 349 * 350 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned 351 * string is from the sentence start at or before the offset to the sentence 352 * start after the offset. 353 * 354 * The returned string will contain the sentence at the offset if the offset 355 * is inside a sentence and will contain the sentence before the offset 356 * if the offset is not inside a sentence. 357 * 358 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned 359 * string is from the line start at or before the offset to the line 360 * start after the offset. 361 * 362 * Deprecated: This method is deprecated since ATK version 363 * 2.9.4. Please use atk_text_get_string_at_offset() instead. 364 * 365 * Params: 366 * offset = position 367 * boundaryType = An #AtkTextBoundary 368 * startOffset = the starting character offset of the returned string 369 * endOffset = the offset of the first character after the 370 * returned substring 371 * 372 * Returns: a newly allocated string containing the text at @offset bounded 373 * by the specified @boundary_type. Use g_free() to free the returned 374 * string. 375 */ 376 public string getTextAtOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset); 377 378 /** 379 * Gets the specified text. 380 * 381 * Deprecated: Please use atk_text_get_string_at_offset() instead. 382 * 383 * Params: 384 * offset = position 385 * boundaryType = An #AtkTextBoundary 386 * startOffset = the starting character offset of the returned string 387 * endOffset = the offset of the first character after the 388 * returned substring 389 * 390 * Returns: a newly allocated string containing the text before @offset bounded 391 * by the specified @boundary_type. Use g_free() to free the returned 392 * string. 393 */ 394 public string getTextBeforeOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset); 395 396 /** 397 * Removes the specified selection. 398 * 399 * Params: 400 * selectionNum = The selection number. The selected regions are 401 * assigned numbers that correspond to how far the region is from the 402 * start of the text. The selected region closest to the beginning 403 * of the text region is assigned the number 0, etc. Note that adding, 404 * moving or deleting a selected region can change the numbering. 405 * 406 * Returns: %TRUE if successful, %FALSE otherwise 407 */ 408 public bool removeSelection(int selectionNum); 409 410 /** 411 * Makes a substring of @text visible on the screen by scrolling all necessary parents. 412 * 413 * Params: 414 * startOffset = start offset in the @text 415 * endOffset = end offset in the @text, or -1 for the end of the text. 416 * type = specify where the object should be made visible. 417 * 418 * Returns: whether scrolling was successful. 419 * 420 * Since: 2.32 421 */ 422 public bool scrollSubstringTo(int startOffset, int endOffset, AtkScrollType type); 423 424 /** 425 * Move the top-left of a substring of @text to a given position of the screen 426 * by scrolling all necessary parents. 427 * 428 * Params: 429 * startOffset = start offset in the @text 430 * endOffset = end offset in the @text, or -1 for the end of the text. 431 * coords = specify whether coordinates are relative to the screen or to the 432 * parent object. 433 * x = x-position where to scroll to 434 * y = y-position where to scroll to 435 * 436 * Returns: whether scrolling was successful. 437 * 438 * Since: 2.32 439 */ 440 public bool scrollSubstringToPoint(int startOffset, int endOffset, AtkCoordType coords, int x, int y); 441 442 /** 443 * Sets the caret (cursor) position to the specified @offset. 444 * 445 * In the case of rich-text content, this method should either grab focus 446 * or move the sequential focus navigation starting point (if the application 447 * supports this concept) as if the user had clicked on the new caret position. 448 * Typically, this means that the target of this operation is the node containing 449 * the new caret position or one of its ancestors. In other words, after this 450 * method is called, if the user advances focus, it should move to the first 451 * focusable node following the new caret position. 452 * 453 * Calling this method should also scroll the application viewport in a way 454 * that matches the behavior of the application's typical caret motion or tab 455 * navigation as closely as possible. This also means that if the application's 456 * caret motion or focus navigation does not trigger a scroll operation, this 457 * method should not trigger one either. If the application does not have a caret 458 * motion or focus navigation operation, this method should try to scroll the new 459 * caret position into view while minimizing unnecessary scroll motion. 460 * 461 * Params: 462 * offset = the character offset of the new caret position 463 * 464 * Returns: %TRUE if successful, %FALSE otherwise. 465 */ 466 public bool setCaretOffset(int offset); 467 468 /** 469 * Changes the start and end offset of the specified selection. 470 * 471 * Params: 472 * selectionNum = The selection number. The selected regions are 473 * assigned numbers that correspond to how far the region is from the 474 * start of the text. The selected region closest to the beginning 475 * of the text region is assigned the number 0, etc. Note that adding, 476 * moving or deleting a selected region can change the numbering. 477 * startOffset = the new starting character offset of the selection 478 * endOffset = the new end position of (e.g. offset immediately past) 479 * the selection 480 * 481 * Returns: %TRUE if successful, %FALSE otherwise 482 */ 483 public bool setSelection(int selectionNum, int startOffset, int endOffset); 484 485 /** 486 * The "text-attributes-changed" signal is emitted when the text 487 * attributes of the text of an object which implements AtkText 488 * changes. 489 */ 490 gulong addOnTextAttributesChanged(void delegate(TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0); 491 492 /** 493 * The "text-caret-moved" signal is emitted when the caret 494 * position of the text of an object which implements AtkText 495 * changes. 496 * 497 * Params: 498 * arg1 = The new position of the text caret. 499 */ 500 gulong addOnTextCaretMoved(void delegate(int, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0); 501 502 /** 503 * The "text-changed" signal is emitted when the text of the 504 * object which implements the AtkText interface changes, This 505 * signal will have a detail which is either "insert" or 506 * "delete" which identifies whether the text change was an 507 * insertion or a deletion. 508 * 509 * Deprecated: Use #AtkObject::text-insert or 510 * #AtkObject::text-remove instead. 511 * 512 * Params: 513 * arg1 = The position (character offset) of the insertion or deletion. 514 * arg2 = The length (in characters) of text inserted or deleted. 515 */ 516 gulong addOnTextChanged(void delegate(int, int, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0); 517 518 /** 519 * The "text-insert" signal is emitted when a new text is 520 * inserted. If the signal was not triggered by the user 521 * (e.g. typing or pasting text), the "system" detail should be 522 * included. 523 * 524 * Params: 525 * arg1 = The position (character offset) of the insertion. 526 * arg2 = The length (in characters) of text inserted. 527 * arg3 = The new text inserted 528 */ 529 gulong addOnTextInsert(void delegate(int, int, string, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0); 530 531 /** 532 * The "text-remove" signal is emitted when a new text is 533 * removed. If the signal was not triggered by the user 534 * (e.g. typing or pasting text), the "system" detail should be 535 * included. 536 * 537 * Params: 538 * arg1 = The position (character offset) of the removal. 539 * arg2 = The length (in characters) of text removed. 540 * arg3 = The old text removed 541 */ 542 gulong addOnTextRemove(void delegate(int, int, string, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0); 543 544 /** 545 * The "text-selection-changed" signal is emitted when the 546 * selected text of an object which implements AtkText changes. 547 */ 548 gulong addOnTextSelectionChanged(void delegate(TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0); 549 550 /** 551 * Frees the memory used by an #AtkAttributeSet, including all its 552 * #AtkAttributes. 553 * 554 * Params: 555 * attribSet = The #AtkAttributeSet to free 556 */ 557 public static void attributeSetFree(AtkAttributeSet* attribSet) 558 { 559 atk_attribute_set_free(attribSet); 560 } 561 562 /** 563 * Get the #AtkTextAttribute type corresponding to a text attribute name. 564 * 565 * Params: 566 * name = a string which is the (non-localized) name of an ATK text attribute. 567 * 568 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified 569 * name, or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute 570 * is found. 571 */ 572 public static AtkTextAttribute attributeForName(string name) 573 { 574 return atk_text_attribute_for_name(Str.toStringz(name)); 575 } 576 577 /** 578 * Gets the name corresponding to the #AtkTextAttribute 579 * 580 * Params: 581 * attr = The #AtkTextAttribute whose name is required 582 * 583 * Returns: a string containing the name; this string should not be freed 584 */ 585 public static string attributeGetName(AtkTextAttribute attr) 586 { 587 return Str.toString(atk_text_attribute_get_name(attr)); 588 } 589 590 /** 591 * Gets the value for the index of the #AtkTextAttribute 592 * 593 * Params: 594 * attr = The #AtkTextAttribute for which a value is required 595 * index = The index of the required value 596 * 597 * Returns: a string containing the value; this string 598 * should not be freed; %NULL is returned if there are no values 599 * maintained for the attr value. 600 */ 601 public static string attributeGetValue(AtkTextAttribute attr, int index) 602 { 603 return Str.toString(atk_text_attribute_get_value(attr, index)); 604 } 605 606 /** 607 * Associate @name with a new #AtkTextAttribute 608 * 609 * Params: 610 * name = a name string 611 * 612 * Returns: an #AtkTextAttribute associated with @name 613 */ 614 public static AtkTextAttribute attributeRegister(string name) 615 { 616 return atk_text_attribute_register(Str.toStringz(name)); 617 } 618 }