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