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 start position of the selected region 74 * endOffset = the offset of the first character after the selected region. 75 * 76 * Returns: %TRUE if success, %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 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 /** 493 * The "text-attributes-changed" signal is emitted when the text 494 * attributes of the text of an object which implements AtkText 495 * changes. 496 */ 497 gulong addOnTextAttributesChanged(void delegate(TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 498 { 499 return Signals.connect(this, "text-attributes-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 500 } 501 502 /** 503 * The "text-caret-moved" signal is emitted when the caret 504 * position of the text of an object which implements AtkText 505 * changes. 506 * 507 * Params: 508 * arg1 = The new position of the text caret. 509 */ 510 gulong addOnTextCaretMoved(void delegate(int, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 511 { 512 return Signals.connect(this, "text-caret-moved", dlg, connectFlags ^ ConnectFlags.SWAPPED); 513 } 514 515 /** 516 * The "text-changed" signal is emitted when the text of the 517 * object which implements the AtkText interface changes, This 518 * signal will have a detail which is either "insert" or 519 * "delete" which identifies whether the text change was an 520 * insertion or a deletion. 521 * 522 * Deprecated: Use #AtkObject::text-insert or 523 * #AtkObject::text-remove instead. 524 * 525 * Params: 526 * arg1 = The position (character offset) of the insertion or deletion. 527 * arg2 = The length (in characters) of text inserted or deleted. 528 */ 529 gulong addOnTextChanged(void delegate(int, int, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 530 { 531 return Signals.connect(this, "text-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 532 } 533 534 /** 535 * The "text-insert" signal is emitted when a new text is 536 * inserted. If the signal was not triggered by the user 537 * (e.g. typing or pasting text), the "system" detail should be 538 * included. 539 * 540 * Params: 541 * arg1 = The position (character offset) of the insertion. 542 * arg2 = The length (in characters) of text inserted. 543 * arg3 = The new text inserted 544 */ 545 gulong addOnTextInsert(void delegate(int, int, string, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 546 { 547 return Signals.connect(this, "text-insert", dlg, connectFlags ^ ConnectFlags.SWAPPED); 548 } 549 550 /** 551 * The "text-remove" signal is emitted when a new text is 552 * removed. If the signal was not triggered by the user 553 * (e.g. typing or pasting text), the "system" detail should be 554 * included. 555 * 556 * Params: 557 * arg1 = The position (character offset) of the removal. 558 * arg2 = The length (in characters) of text removed. 559 * arg3 = The old text removed 560 */ 561 gulong addOnTextRemove(void delegate(int, int, string, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 562 { 563 return Signals.connect(this, "text-remove", dlg, connectFlags ^ ConnectFlags.SWAPPED); 564 } 565 566 /** 567 * The "text-selection-changed" signal is emitted when the 568 * selected text of an object which implements AtkText changes. 569 */ 570 gulong addOnTextSelectionChanged(void delegate(TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 571 { 572 return Signals.connect(this, "text-selection-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 573 } 574 }