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 	 * Frees the memory associated with an array of AtkTextRange. It is assumed
71 	 * that the array was returned by the function atk_text_get_bounded_ranges
72 	 * and is NULL terminated.
73 	 *
74 	 * Params:
75 	 *     ranges = A pointer to an array of #AtkTextRange which is
76 	 *         to be freed.
77 	 *
78 	 * Since: 1.3
79 	 */
80 	public static void freeRanges(TextRange[] ranges)
81 	{
82 		AtkTextRange*[] rangesArray = new AtkTextRange*[ranges.length];
83 		for ( int i = 0; i < ranges.length; i++ )
84 		{
85 			rangesArray[i] = ranges[i].getTextRangeStruct();
86 		}
87 
88 		atk_text_free_ranges(rangesArray.ptr);
89 	}
90 
91 	/**
92 	 * Adds a selection bounded by the specified offsets.
93 	 *
94 	 * Params:
95 	 *     startOffset = the start position of the selected region
96 	 *     endOffset = the offset of the first character after the selected region.
97 	 *
98 	 * Returns: %TRUE if success, %FALSE otherwise
99 	 */
100 	public bool addSelection(int startOffset, int endOffset)
101 	{
102 		return atk_text_add_selection(getTextStruct(), startOffset, endOffset) != 0;
103 	}
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 		auto p = atk_text_get_bounded_ranges(getTextStruct(), rect, coordType, xClipType, yClipType);
122 
123 		if(p is null)
124 		{
125 			return null;
126 		}
127 
128 		TextRange[] arr = new TextRange[getArrayLength(p)];
129 		for(int i = 0; i < getArrayLength(p); i++)
130 		{
131 			arr[i] = ObjectG.getDObject!(TextRange)(cast(AtkTextRange*) p[i]);
132 		}
133 
134 		return arr;
135 	}
136 
137 	/**
138 	 * Gets the offset position of the caret (cursor).
139 	 *
140 	 * Returns: the offset position of the caret (cursor).
141 	 */
142 	public int getCaretOffset()
143 	{
144 		return atk_text_get_caret_offset(getTextStruct());
145 	}
146 
147 	/**
148 	 * Gets the specified text.
149 	 *
150 	 * Params:
151 	 *     offset = position
152 	 *
153 	 * Returns: the character at @offset.
154 	 */
155 	public dchar getCharacterAtOffset(int offset)
156 	{
157 		return atk_text_get_character_at_offset(getTextStruct(), offset);
158 	}
159 
160 	/**
161 	 * Gets the character count.
162 	 *
163 	 * Returns: the number of characters.
164 	 */
165 	public int getCharacterCount()
166 	{
167 		return atk_text_get_character_count(getTextStruct());
168 	}
169 
170 	/**
171 	 * Get the bounding box containing the glyph representing the character at
172 	 * a particular text offset.
173 	 *
174 	 * Params:
175 	 *     offset = The offset of the text character for which bounding information is required.
176 	 *     x = Pointer for the x cordinate of the bounding box
177 	 *     y = Pointer for the y cordinate of the bounding box
178 	 *     width = Pointer for the width of the bounding box
179 	 *     height = Pointer for the height of the bounding box
180 	 *     coords = specify whether coordinates are relative to the screen or widget window
181 	 */
182 	public void getCharacterExtents(int offset, out int x, out int y, out int width, out int height, AtkCoordType coords)
183 	{
184 		atk_text_get_character_extents(getTextStruct(), offset, &x, &y, &width, &height, coords);
185 	}
186 
187 	/**
188 	 * Creates an #AtkAttributeSet which consists of the default values of
189 	 * attributes for the text. See the enum AtkTextAttribute for types of text
190 	 * attributes that can be returned. Note that other attributes may also be
191 	 * returned.
192 	 *
193 	 * Returns: an #AtkAttributeSet which contains the default
194 	 *     values of attributes.  at @offset. this #atkattributeset should be freed by
195 	 *     a call to atk_attribute_set_free().
196 	 */
197 	public AtkAttributeSet* getDefaultAttributes()
198 	{
199 		return atk_text_get_default_attributes(getTextStruct());
200 	}
201 
202 	/**
203 	 * Gets the number of selected regions.
204 	 *
205 	 * Returns: The number of selected regions, or -1 if a failure
206 	 *     occurred.
207 	 */
208 	public int getNSelections()
209 	{
210 		return atk_text_get_n_selections(getTextStruct());
211 	}
212 
213 	/**
214 	 * Gets the offset of the character located at coordinates @x and @y. @x and @y
215 	 * are interpreted as being relative to the screen or this widget's window
216 	 * depending on @coords.
217 	 *
218 	 * Params:
219 	 *     x = screen x-position of character
220 	 *     y = screen y-position of character
221 	 *     coords = specify whether coordinates are relative to the screen or
222 	 *         widget window
223 	 *
224 	 * Returns: the offset to the character which is located at
225 	 *     the specified @x and @y coordinates.
226 	 */
227 	public int getOffsetAtPoint(int x, int y, AtkCoordType coords)
228 	{
229 		return atk_text_get_offset_at_point(getTextStruct(), x, y, coords);
230 	}
231 
232 	/**
233 	 * Get the bounding box for text within the specified range.
234 	 *
235 	 * Params:
236 	 *     startOffset = The offset of the first text character for which boundary
237 	 *         information is required.
238 	 *     endOffset = The offset of the text character after the last character
239 	 *         for which boundary information is required.
240 	 *     coordType = Specify whether coordinates are relative to the screen or widget window.
241 	 *     rect = A pointer to a AtkTextRectangle which is filled in by this function.
242 	 *
243 	 * Since: 1.3
244 	 */
245 	public void getRangeExtents(int startOffset, int endOffset, AtkCoordType coordType, out AtkTextRectangle rect)
246 	{
247 		atk_text_get_range_extents(getTextStruct(), startOffset, endOffset, coordType, &rect);
248 	}
249 
250 	/**
251 	 * Creates an #AtkAttributeSet which consists of the attributes explicitly
252 	 * set at the position @offset in the text. @start_offset and @end_offset are
253 	 * set to the start and end of the range around @offset where the attributes are
254 	 * invariant. Note that @end_offset is the offset of the first character
255 	 * after the range.  See the enum AtkTextAttribute for types of text
256 	 * attributes that can be returned. Note that other attributes may also be
257 	 * returned.
258 	 *
259 	 * Params:
260 	 *     offset = the offset at which to get the attributes, -1 means the offset of
261 	 *         the character to be inserted at the caret location.
262 	 *     startOffset = the address to put the start offset of the range
263 	 *     endOffset = the address to put the end offset of the range
264 	 *
265 	 * Returns: an #AtkAttributeSet which contains the attributes
266 	 *     explicitly set at @offset. This #AtkAttributeSet should be freed by a call
267 	 *     to atk_attribute_set_free().
268 	 */
269 	public AtkAttributeSet* getRunAttributes(int offset, out int startOffset, out int endOffset)
270 	{
271 		return atk_text_get_run_attributes(getTextStruct(), offset, &startOffset, &endOffset);
272 	}
273 
274 	/**
275 	 * Gets the text from the specified selection.
276 	 *
277 	 * Params:
278 	 *     selectionNum = The selection number.  The selected regions are
279 	 *         assigned numbers that correspond to how far the region is from the
280 	 *         start of the text.  The selected region closest to the beginning
281 	 *         of the text region is assigned the number 0, etc.  Note that adding,
282 	 *         moving or deleting a selected region can change the numbering.
283 	 *     startOffset = passes back the start position of the selected region
284 	 *     endOffset = passes back the end position of (e.g. offset immediately past)
285 	 *         the selected region
286 	 *
287 	 * Returns: a newly allocated string containing the selected text. Use g_free()
288 	 *     to free the returned string.
289 	 */
290 	public string getSelection(int selectionNum, out int startOffset, out int endOffset)
291 	{
292 		auto retStr = atk_text_get_selection(getTextStruct(), selectionNum, &startOffset, &endOffset);
293 
294 		scope(exit) Str.freeString(retStr);
295 		return Str.toString(retStr);
296 	}
297 
298 	/**
299 	 * Gets a portion of the text exposed through an #AtkText according to a given @offset
300 	 * and a specific @granularity, along with the start and end offsets defining the
301 	 * boundaries of such a portion of text.
302 	 *
303 	 * If @granularity is ATK_TEXT_GRANULARITY_CHAR the character at the
304 	 * offset is returned.
305 	 *
306 	 * If @granularity is ATK_TEXT_GRANULARITY_WORD the returned string
307 	 * is from the word start at or before the offset to the word start after
308 	 * the offset.
309 	 *
310 	 * The returned string will contain the word at the offset if the offset
311 	 * is inside a word and will contain the word before the offset if the
312 	 * offset is not inside a word.
313 	 *
314 	 * If @granularity is ATK_TEXT_GRANULARITY_SENTENCE the returned string
315 	 * is from the sentence start at or before the offset to the sentence
316 	 * start after the offset.
317 	 *
318 	 * The returned string will contain the sentence at the offset if the offset
319 	 * is inside a sentence and will contain the sentence before the offset
320 	 * if the offset is not inside a sentence.
321 	 *
322 	 * If @granularity is ATK_TEXT_GRANULARITY_LINE the returned string
323 	 * is from the line start at or before the offset to the line
324 	 * start after the offset.
325 	 *
326 	 * If @granularity is ATK_TEXT_GRANULARITY_PARAGRAPH the returned string
327 	 * is from the start of the paragraph at or before the offset to the start
328 	 * of the following paragraph after the offset.
329 	 *
330 	 * Params:
331 	 *     offset = position
332 	 *     granularity = An #AtkTextGranularity
333 	 *     startOffset = the start offset of the returned string, or -1
334 	 *         if an error has occurred (e.g. invalid offset, not implemented)
335 	 *     endOffset = the offset of the first character after the returned string,
336 	 *         or -1 if an error has occurred (e.g. invalid offset, not implemented)
337 	 *
338 	 * Returns: a newly allocated string containing the text
339 	 *     at the @offset bounded by the specified @granularity. Use
340 	 *     g_free() to free the returned string.  Returns %NULL if the
341 	 *     offset is invalid or no implementation is available.
342 	 *
343 	 * Since: 2.10
344 	 */
345 	public string getStringAtOffset(int offset, AtkTextGranularity granularity, out int startOffset, out int endOffset)
346 	{
347 		auto retStr = atk_text_get_string_at_offset(getTextStruct(), offset, granularity, &startOffset, &endOffset);
348 
349 		scope(exit) Str.freeString(retStr);
350 		return Str.toString(retStr);
351 	}
352 
353 	/**
354 	 * Gets the specified text.
355 	 *
356 	 * Params:
357 	 *     startOffset = start position
358 	 *     endOffset = end position, or -1 for the end of the string.
359 	 *
360 	 * Returns: a newly allocated string containing the text from @start_offset up
361 	 *     to, but not including @end_offset. Use g_free() to free the returned string.
362 	 */
363 	public string getText(int startOffset, int endOffset)
364 	{
365 		auto retStr = atk_text_get_text(getTextStruct(), startOffset, endOffset);
366 
367 		scope(exit) Str.freeString(retStr);
368 		return Str.toString(retStr);
369 	}
370 
371 	/**
372 	 * Gets the specified text.
373 	 *
374 	 * Deprecated: Please use atk_text_get_string_at_offset() instead.
375 	 *
376 	 * Params:
377 	 *     offset = position
378 	 *     boundaryType = An #AtkTextBoundary
379 	 *     startOffset = the start offset of the returned string
380 	 *     endOffset = the offset of the first character after the
381 	 *         returned substring
382 	 *
383 	 * Returns: a newly allocated string containing the text after @offset bounded
384 	 *     by the specified @boundary_type. Use g_free() to free the returned string.
385 	 */
386 	public string getTextAfterOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset)
387 	{
388 		auto retStr = atk_text_get_text_after_offset(getTextStruct(), offset, boundaryType, &startOffset, &endOffset);
389 
390 		scope(exit) Str.freeString(retStr);
391 		return Str.toString(retStr);
392 	}
393 
394 	/**
395 	 * Gets the specified text.
396 	 *
397 	 * If the boundary_type if ATK_TEXT_BOUNDARY_CHAR the character at the
398 	 * offset is returned.
399 	 *
400 	 * If the boundary_type is ATK_TEXT_BOUNDARY_WORD_START the returned string
401 	 * is from the word start at or before the offset to the word start after
402 	 * the offset.
403 	 *
404 	 * The returned string will contain the word at the offset if the offset
405 	 * is inside a word and will contain the word before the offset if the
406 	 * offset is not inside a word.
407 	 *
408 	 * If the boundary type is ATK_TEXT_BOUNDARY_SENTENCE_START the returned
409 	 * string is from the sentence start at or before the offset to the sentence
410 	 * start after the offset.
411 	 *
412 	 * The returned string will contain the sentence at the offset if the offset
413 	 * is inside a sentence and will contain the sentence before the offset
414 	 * if the offset is not inside a sentence.
415 	 *
416 	 * If the boundary type is ATK_TEXT_BOUNDARY_LINE_START the returned
417 	 * string is from the line start at or before the offset to the line
418 	 * start after the offset.
419 	 *
420 	 * Deprecated: This method is deprecated since ATK version
421 	 * 2.9.4. Please use atk_text_get_string_at_offset() instead.
422 	 *
423 	 * Params:
424 	 *     offset = position
425 	 *     boundaryType = An #AtkTextBoundary
426 	 *     startOffset = the start offset of the returned string
427 	 *     endOffset = the offset of the first character after the
428 	 *         returned substring
429 	 *
430 	 * Returns: a newly allocated string containing the text at @offset bounded by
431 	 *     the specified @boundary_type. Use g_free() to free the returned string.
432 	 */
433 	public string getTextAtOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset)
434 	{
435 		auto retStr = atk_text_get_text_at_offset(getTextStruct(), offset, boundaryType, &startOffset, &endOffset);
436 
437 		scope(exit) Str.freeString(retStr);
438 		return Str.toString(retStr);
439 	}
440 
441 	/**
442 	 * Gets the specified text.
443 	 *
444 	 * Deprecated: Please use atk_text_get_string_at_offset() instead.
445 	 *
446 	 * Params:
447 	 *     offset = position
448 	 *     boundaryType = An #AtkTextBoundary
449 	 *     startOffset = the start offset of the returned string
450 	 *     endOffset = the offset of the first character after the
451 	 *         returned substring
452 	 *
453 	 * Returns: a newly allocated string containing the text before @offset bounded
454 	 *     by the specified @boundary_type. Use g_free() to free the returned string.
455 	 */
456 	public string getTextBeforeOffset(int offset, AtkTextBoundary boundaryType, out int startOffset, out int endOffset)
457 	{
458 		auto retStr = atk_text_get_text_before_offset(getTextStruct(), offset, boundaryType, &startOffset, &endOffset);
459 
460 		scope(exit) Str.freeString(retStr);
461 		return Str.toString(retStr);
462 	}
463 
464 	/**
465 	 * Removes the specified selection.
466 	 *
467 	 * Params:
468 	 *     selectionNum = The selection number.  The selected regions are
469 	 *         assigned numbers that correspond to how far the region is from the
470 	 *         start of the text.  The selected region closest to the beginning
471 	 *         of the text region is assigned the number 0, etc.  Note that adding,
472 	 *         moving or deleting a selected region can change the numbering.
473 	 *
474 	 * Returns: %TRUE if success, %FALSE otherwise
475 	 */
476 	public bool removeSelection(int selectionNum)
477 	{
478 		return atk_text_remove_selection(getTextStruct(), selectionNum) != 0;
479 	}
480 
481 	/**
482 	 * Sets the caret (cursor) position to the specified @offset.
483 	 *
484 	 * Params:
485 	 *     offset = position
486 	 *
487 	 * Returns: %TRUE if success, %FALSE otherwise.
488 	 */
489 	public bool setCaretOffset(int offset)
490 	{
491 		return atk_text_set_caret_offset(getTextStruct(), offset) != 0;
492 	}
493 
494 	/**
495 	 * Changes the start and end offset of the specified selection.
496 	 *
497 	 * Params:
498 	 *     selectionNum = The selection number.  The selected regions are
499 	 *         assigned numbers that correspond to how far the region is from the
500 	 *         start of the text.  The selected region closest to the beginning
501 	 *         of the text region is assigned the number 0, etc.  Note that adding,
502 	 *         moving or deleting a selected region can change the numbering.
503 	 *     startOffset = the new start position of the selection
504 	 *     endOffset = the new end position of (e.g. offset immediately past)
505 	 *         the selection
506 	 *
507 	 * Returns: %TRUE if success, %FALSE otherwise
508 	 */
509 	public bool setSelection(int selectionNum, int startOffset, int endOffset)
510 	{
511 		return atk_text_set_selection(getTextStruct(), selectionNum, startOffset, endOffset) != 0;
512 	}
513 
514 	protected class OnTextAttributesChangedDelegateWrapper
515 	{
516 		void delegate(TextIF) dlg;
517 		gulong handlerId;
518 
519 		this(void delegate(TextIF) dlg)
520 		{
521 			this.dlg = dlg;
522 			onTextAttributesChangedListeners ~= this;
523 		}
524 
525 		void remove(OnTextAttributesChangedDelegateWrapper source)
526 		{
527 			foreach(index, wrapper; onTextAttributesChangedListeners)
528 			{
529 				if (wrapper.handlerId == source.handlerId)
530 				{
531 					onTextAttributesChangedListeners[index] = null;
532 					onTextAttributesChangedListeners = std.algorithm.remove(onTextAttributesChangedListeners, index);
533 					break;
534 				}
535 			}
536 		}
537 	}
538 	OnTextAttributesChangedDelegateWrapper[] onTextAttributesChangedListeners;
539 
540 	/**
541 	 * The "text-attributes-changed" signal is emitted when the text
542 	 * attributes of the text of an object which implements AtkText
543 	 * changes.
544 	 */
545 	gulong addOnTextAttributesChanged(void delegate(TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
546 	{
547 		auto wrapper = new OnTextAttributesChangedDelegateWrapper(dlg);
548 		wrapper.handlerId = Signals.connectData(
549 			this,
550 			"text-attributes-changed",
551 			cast(GCallback)&callBackTextAttributesChanged,
552 			cast(void*)wrapper,
553 			cast(GClosureNotify)&callBackTextAttributesChangedDestroy,
554 			connectFlags);
555 		return wrapper.handlerId;
556 	}
557 
558 	extern(C) static void callBackTextAttributesChanged(AtkText* textStruct, OnTextAttributesChangedDelegateWrapper wrapper)
559 	{
560 		wrapper.dlg(wrapper.outer);
561 	}
562 
563 	extern(C) static void callBackTextAttributesChangedDestroy(OnTextAttributesChangedDelegateWrapper wrapper, GClosure* closure)
564 	{
565 		wrapper.remove(wrapper);
566 	}
567 
568 	protected class OnTextCaretMovedDelegateWrapper
569 	{
570 		void delegate(int, TextIF) dlg;
571 		gulong handlerId;
572 
573 		this(void delegate(int, TextIF) dlg)
574 		{
575 			this.dlg = dlg;
576 			onTextCaretMovedListeners ~= this;
577 		}
578 
579 		void remove(OnTextCaretMovedDelegateWrapper source)
580 		{
581 			foreach(index, wrapper; onTextCaretMovedListeners)
582 			{
583 				if (wrapper.handlerId == source.handlerId)
584 				{
585 					onTextCaretMovedListeners[index] = null;
586 					onTextCaretMovedListeners = std.algorithm.remove(onTextCaretMovedListeners, index);
587 					break;
588 				}
589 			}
590 		}
591 	}
592 	OnTextCaretMovedDelegateWrapper[] onTextCaretMovedListeners;
593 
594 	/**
595 	 * The "text-caret-moved" signal is emitted when the caret
596 	 * position of the text of an object which implements AtkText
597 	 * changes.
598 	 *
599 	 * Params:
600 	 *     arg1 = The new position of the text caret.
601 	 */
602 	gulong addOnTextCaretMoved(void delegate(int, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
603 	{
604 		auto wrapper = new OnTextCaretMovedDelegateWrapper(dlg);
605 		wrapper.handlerId = Signals.connectData(
606 			this,
607 			"text-caret-moved",
608 			cast(GCallback)&callBackTextCaretMoved,
609 			cast(void*)wrapper,
610 			cast(GClosureNotify)&callBackTextCaretMovedDestroy,
611 			connectFlags);
612 		return wrapper.handlerId;
613 	}
614 
615 	extern(C) static void callBackTextCaretMoved(AtkText* textStruct, int arg1, OnTextCaretMovedDelegateWrapper wrapper)
616 	{
617 		wrapper.dlg(arg1, wrapper.outer);
618 	}
619 
620 	extern(C) static void callBackTextCaretMovedDestroy(OnTextCaretMovedDelegateWrapper wrapper, GClosure* closure)
621 	{
622 		wrapper.remove(wrapper);
623 	}
624 
625 	protected class OnTextChangedDelegateWrapper
626 	{
627 		void delegate(int, int, TextIF) dlg;
628 		gulong handlerId;
629 
630 		this(void delegate(int, int, TextIF) dlg)
631 		{
632 			this.dlg = dlg;
633 			onTextChangedListeners ~= this;
634 		}
635 
636 		void remove(OnTextChangedDelegateWrapper source)
637 		{
638 			foreach(index, wrapper; onTextChangedListeners)
639 			{
640 				if (wrapper.handlerId == source.handlerId)
641 				{
642 					onTextChangedListeners[index] = null;
643 					onTextChangedListeners = std.algorithm.remove(onTextChangedListeners, index);
644 					break;
645 				}
646 			}
647 		}
648 	}
649 	OnTextChangedDelegateWrapper[] onTextChangedListeners;
650 
651 	/**
652 	 * The "text-changed" signal is emitted when the text of the
653 	 * object which implements the AtkText interface changes, This
654 	 * signal will have a detail which is either "insert" or
655 	 * "delete" which identifies whether the text change was an
656 	 * insertion or a deletion.
657 	 *
658 	 * Deprecated: Use #AtkObject::text-insert or
659 	 * #AtkObject::text-remove instead.
660 	 *
661 	 * Params:
662 	 *     arg1 = The position (character offset) of the insertion or deletion.
663 	 *     arg2 = The length (in characters) of text inserted or deleted.
664 	 */
665 	gulong addOnTextChanged(void delegate(int, int, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
666 	{
667 		auto wrapper = new OnTextChangedDelegateWrapper(dlg);
668 		wrapper.handlerId = Signals.connectData(
669 			this,
670 			"text-changed",
671 			cast(GCallback)&callBackTextChanged,
672 			cast(void*)wrapper,
673 			cast(GClosureNotify)&callBackTextChangedDestroy,
674 			connectFlags);
675 		return wrapper.handlerId;
676 	}
677 
678 	extern(C) static void callBackTextChanged(AtkText* textStruct, int arg1, int arg2, OnTextChangedDelegateWrapper wrapper)
679 	{
680 		wrapper.dlg(arg1, arg2, wrapper.outer);
681 	}
682 
683 	extern(C) static void callBackTextChangedDestroy(OnTextChangedDelegateWrapper wrapper, GClosure* closure)
684 	{
685 		wrapper.remove(wrapper);
686 	}
687 
688 	protected class OnTextInsertDelegateWrapper
689 	{
690 		void delegate(int, int, string, TextIF) dlg;
691 		gulong handlerId;
692 
693 		this(void delegate(int, int, string, TextIF) dlg)
694 		{
695 			this.dlg = dlg;
696 			onTextInsertListeners ~= this;
697 		}
698 
699 		void remove(OnTextInsertDelegateWrapper source)
700 		{
701 			foreach(index, wrapper; onTextInsertListeners)
702 			{
703 				if (wrapper.handlerId == source.handlerId)
704 				{
705 					onTextInsertListeners[index] = null;
706 					onTextInsertListeners = std.algorithm.remove(onTextInsertListeners, index);
707 					break;
708 				}
709 			}
710 		}
711 	}
712 	OnTextInsertDelegateWrapper[] onTextInsertListeners;
713 
714 	/**
715 	 * The "text-insert" signal is emitted when a new text is
716 	 * inserted. If the signal was not triggered by the user
717 	 * (e.g. typing or pasting text), the "system" detail should be
718 	 * included.
719 	 *
720 	 * Params:
721 	 *     arg1 = The position (character offset) of the insertion.
722 	 *     arg2 = The length (in characters) of text inserted.
723 	 *     arg3 = The new text inserted
724 	 */
725 	gulong addOnTextInsert(void delegate(int, int, string, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
726 	{
727 		auto wrapper = new OnTextInsertDelegateWrapper(dlg);
728 		wrapper.handlerId = Signals.connectData(
729 			this,
730 			"text-insert",
731 			cast(GCallback)&callBackTextInsert,
732 			cast(void*)wrapper,
733 			cast(GClosureNotify)&callBackTextInsertDestroy,
734 			connectFlags);
735 		return wrapper.handlerId;
736 	}
737 
738 	extern(C) static void callBackTextInsert(AtkText* textStruct, int arg1, int arg2, char* arg3, OnTextInsertDelegateWrapper wrapper)
739 	{
740 		wrapper.dlg(arg1, arg2, Str.toString(arg3), wrapper.outer);
741 	}
742 
743 	extern(C) static void callBackTextInsertDestroy(OnTextInsertDelegateWrapper wrapper, GClosure* closure)
744 	{
745 		wrapper.remove(wrapper);
746 	}
747 
748 	protected class OnTextRemoveDelegateWrapper
749 	{
750 		void delegate(int, int, string, TextIF) dlg;
751 		gulong handlerId;
752 
753 		this(void delegate(int, int, string, TextIF) dlg)
754 		{
755 			this.dlg = dlg;
756 			onTextRemoveListeners ~= this;
757 		}
758 
759 		void remove(OnTextRemoveDelegateWrapper source)
760 		{
761 			foreach(index, wrapper; onTextRemoveListeners)
762 			{
763 				if (wrapper.handlerId == source.handlerId)
764 				{
765 					onTextRemoveListeners[index] = null;
766 					onTextRemoveListeners = std.algorithm.remove(onTextRemoveListeners, index);
767 					break;
768 				}
769 			}
770 		}
771 	}
772 	OnTextRemoveDelegateWrapper[] onTextRemoveListeners;
773 
774 	/**
775 	 * The "text-remove" signal is emitted when a new text is
776 	 * removed. If the signal was not triggered by the user
777 	 * (e.g. typing or pasting text), the "system" detail should be
778 	 * included.
779 	 *
780 	 * Params:
781 	 *     arg1 = The position (character offset) of the removal.
782 	 *     arg2 = The length (in characters) of text removed.
783 	 *     arg3 = The old text removed
784 	 */
785 	gulong addOnTextRemove(void delegate(int, int, string, TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
786 	{
787 		auto wrapper = new OnTextRemoveDelegateWrapper(dlg);
788 		wrapper.handlerId = Signals.connectData(
789 			this,
790 			"text-remove",
791 			cast(GCallback)&callBackTextRemove,
792 			cast(void*)wrapper,
793 			cast(GClosureNotify)&callBackTextRemoveDestroy,
794 			connectFlags);
795 		return wrapper.handlerId;
796 	}
797 
798 	extern(C) static void callBackTextRemove(AtkText* textStruct, int arg1, int arg2, char* arg3, OnTextRemoveDelegateWrapper wrapper)
799 	{
800 		wrapper.dlg(arg1, arg2, Str.toString(arg3), wrapper.outer);
801 	}
802 
803 	extern(C) static void callBackTextRemoveDestroy(OnTextRemoveDelegateWrapper wrapper, GClosure* closure)
804 	{
805 		wrapper.remove(wrapper);
806 	}
807 
808 	protected class OnTextSelectionChangedDelegateWrapper
809 	{
810 		void delegate(TextIF) dlg;
811 		gulong handlerId;
812 
813 		this(void delegate(TextIF) dlg)
814 		{
815 			this.dlg = dlg;
816 			onTextSelectionChangedListeners ~= this;
817 		}
818 
819 		void remove(OnTextSelectionChangedDelegateWrapper source)
820 		{
821 			foreach(index, wrapper; onTextSelectionChangedListeners)
822 			{
823 				if (wrapper.handlerId == source.handlerId)
824 				{
825 					onTextSelectionChangedListeners[index] = null;
826 					onTextSelectionChangedListeners = std.algorithm.remove(onTextSelectionChangedListeners, index);
827 					break;
828 				}
829 			}
830 		}
831 	}
832 	OnTextSelectionChangedDelegateWrapper[] onTextSelectionChangedListeners;
833 
834 	/**
835 	 * The "text-selection-changed" signal is emitted when the
836 	 * selected text of an object which implements AtkText changes.
837 	 */
838 	gulong addOnTextSelectionChanged(void delegate(TextIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
839 	{
840 		auto wrapper = new OnTextSelectionChangedDelegateWrapper(dlg);
841 		wrapper.handlerId = Signals.connectData(
842 			this,
843 			"text-selection-changed",
844 			cast(GCallback)&callBackTextSelectionChanged,
845 			cast(void*)wrapper,
846 			cast(GClosureNotify)&callBackTextSelectionChangedDestroy,
847 			connectFlags);
848 		return wrapper.handlerId;
849 	}
850 
851 	extern(C) static void callBackTextSelectionChanged(AtkText* textStruct, OnTextSelectionChangedDelegateWrapper wrapper)
852 	{
853 		wrapper.dlg(wrapper.outer);
854 	}
855 
856 	extern(C) static void callBackTextSelectionChangedDestroy(OnTextSelectionChangedDelegateWrapper wrapper, GClosure* closure)
857 	{
858 		wrapper.remove(wrapper);
859 	}
860 
861 	/**
862 	 * Frees the memory used by an #AtkAttributeSet, including all its
863 	 * #AtkAttributes.
864 	 *
865 	 * Params:
866 	 *     attribSet = The #AtkAttributeSet to free
867 	 */
868 	public static void attributeSetFree(AtkAttributeSet* attribSet)
869 	{
870 		atk_attribute_set_free(attribSet);
871 	}
872 
873 	/**
874 	 * Get the #AtkTextAttribute type corresponding to a text attribute name.
875 	 *
876 	 * Params:
877 	 *     name = a string which is the (non-localized) name of an ATK text attribute.
878 	 *
879 	 * Returns: the #AtkTextAttribute enumerated type corresponding to the specified
880 	 *     name,
881 	 *     or #ATK_TEXT_ATTRIBUTE_INVALID if no matching text attribute is found.
882 	 */
883 	public static AtkTextAttribute attributeForName(string name)
884 	{
885 		return atk_text_attribute_for_name(Str.toStringz(name));
886 	}
887 
888 	/**
889 	 * Gets the name corresponding to the #AtkTextAttribute
890 	 *
891 	 * Params:
892 	 *     attr = The #AtkTextAttribute whose name is required
893 	 *
894 	 * Returns: a string containing the name; this string should not be freed
895 	 */
896 	public static string attributeGetName(AtkTextAttribute attr)
897 	{
898 		return Str.toString(atk_text_attribute_get_name(attr));
899 	}
900 
901 	/**
902 	 * Gets the value for the index of the #AtkTextAttribute
903 	 *
904 	 * Params:
905 	 *     attr = The #AtkTextAttribute for which a value is required
906 	 *     index = The index of the required value
907 	 *
908 	 * Returns: a string containing the value; this string
909 	 *     should not be freed; %NULL is returned if there are no values
910 	 *     maintained for the attr value.
911 	 */
912 	public static string attributeGetValue(AtkTextAttribute attr, int index)
913 	{
914 		return Str.toString(atk_text_attribute_get_value(attr, index));
915 	}
916 
917 	/**
918 	 * Associate @name with a new #AtkTextAttribute
919 	 *
920 	 * Params:
921 	 *     name = a name string
922 	 *
923 	 * Returns: an #AtkTextAttribute associated with @name
924 	 */
925 	public static AtkTextAttribute attributeRegister(string name)
926 	{
927 		return atk_text_attribute_register(Str.toStringz(name));
928 	}
929 }