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