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 gtk.TextTagTable;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gtk.BuildableIF;
32 private import gtk.BuildableT;
33 private import gtk.TextTag;
34 public  import gtkc.gdktypes;
35 private import gtkc.gtk;
36 public  import gtkc.gtktypes;
37 private import std.algorithm;
38 
39 
40 /**
41  * You may wish to begin by reading the
42  * [text widget conceptual overview][TextWidget]
43  * which gives an overview of all the objects and
44  * data types related to the text widget and how they work together.
45  * 
46  * # GtkTextTagTables as GtkBuildable
47  * 
48  * The GtkTextTagTable implementation of the GtkBuildable interface
49  * supports adding tags by specifying “tag” as the “type” attribute
50  * of a <child> element.
51  * 
52  * An example of a UI definition fragment specifying tags:
53  * |[
54  * <object class="GtkTextTagTable">
55  * <child type="tag">
56  * <object class="GtkTextTag"/>
57  * </child>
58  * </object>
59  * ]|
60  */
61 public class TextTagTable : ObjectG, BuildableIF
62 {
63 	/** the main Gtk struct */
64 	protected GtkTextTagTable* gtkTextTagTable;
65 
66 	/** Get the main Gtk struct */
67 	public GtkTextTagTable* getTextTagTableStruct()
68 	{
69 		return gtkTextTagTable;
70 	}
71 
72 	/** the main Gtk struct as a void* */
73 	protected override void* getStruct()
74 	{
75 		return cast(void*)gtkTextTagTable;
76 	}
77 
78 	protected override void setStruct(GObject* obj)
79 	{
80 		gtkTextTagTable = cast(GtkTextTagTable*)obj;
81 		super.setStruct(obj);
82 	}
83 
84 	/**
85 	 * Sets our main struct and passes it to the parent class.
86 	 */
87 	public this (GtkTextTagTable* gtkTextTagTable, bool ownedRef = false)
88 	{
89 		this.gtkTextTagTable = gtkTextTagTable;
90 		super(cast(GObject*)gtkTextTagTable, ownedRef);
91 	}
92 
93 	// add the Buildable capabilities
94 	mixin BuildableT!(GtkTextTagTable);
95 
96 
97 	/** */
98 	public static GType getType()
99 	{
100 		return gtk_text_tag_table_get_type();
101 	}
102 
103 	/**
104 	 * Creates a new #GtkTextTagTable. The table contains no tags by
105 	 * default.
106 	 *
107 	 * Return: a new #GtkTextTagTable
108 	 *
109 	 * Throws: ConstructionException GTK+ fails to create the object.
110 	 */
111 	public this()
112 	{
113 		auto p = gtk_text_tag_table_new();
114 		
115 		if(p is null)
116 		{
117 			throw new ConstructionException("null returned by new");
118 		}
119 		
120 		this(cast(GtkTextTagTable*) p, true);
121 	}
122 
123 	/**
124 	 * Add a tag to the table. The tag is assigned the highest priority
125 	 * in the table.
126 	 *
127 	 * @tag must not be in a tag table already, and may not have
128 	 * the same name as an already-added tag.
129 	 *
130 	 * Params:
131 	 *     tag = a #GtkTextTag
132 	 *
133 	 * Return: %TRUE on success.
134 	 */
135 	public bool add(TextTag tag)
136 	{
137 		return gtk_text_tag_table_add(gtkTextTagTable, (tag is null) ? null : tag.getTextTagStruct()) != 0;
138 	}
139 
140 	/**
141 	 * Calls @func on each tag in @table, with user data @data.
142 	 * Note that the table may not be modified while iterating
143 	 * over it (you can’t add/remove tags).
144 	 *
145 	 * Params:
146 	 *     func = a function to call on each tag
147 	 *     data = user data
148 	 */
149 	public void foreac(GtkTextTagTableForeach func, void* data)
150 	{
151 		gtk_text_tag_table_foreach(gtkTextTagTable, func, data);
152 	}
153 
154 	/**
155 	 * Returns the size of the table (number of tags)
156 	 *
157 	 * Return: number of tags in @table
158 	 */
159 	public int getSize()
160 	{
161 		return gtk_text_tag_table_get_size(gtkTextTagTable);
162 	}
163 
164 	/**
165 	 * Look up a named tag.
166 	 *
167 	 * Params:
168 	 *     name = name of a tag
169 	 *
170 	 * Return: The tag, or %NULL if none by that
171 	 *     name is in the table.
172 	 */
173 	public TextTag lookup(string name)
174 	{
175 		auto p = gtk_text_tag_table_lookup(gtkTextTagTable, Str.toStringz(name));
176 		
177 		if(p is null)
178 		{
179 			return null;
180 		}
181 		
182 		return ObjectG.getDObject!(TextTag)(cast(GtkTextTag*) p);
183 	}
184 
185 	/**
186 	 * Remove a tag from the table. If a #GtkTextBuffer has @table as its tag table,
187 	 * the tag is removed from the buffer. The table’s reference to the tag is
188 	 * removed, so the tag will end up destroyed if you don’t have a reference to
189 	 * it.
190 	 *
191 	 * Params:
192 	 *     tag = a #GtkTextTag
193 	 */
194 	public void remove(TextTag tag)
195 	{
196 		gtk_text_tag_table_remove(gtkTextTagTable, (tag is null) ? null : tag.getTextTagStruct());
197 	}
198 
199 	protected class OnTagAddedDelegateWrapper
200 	{
201 		void delegate(TextTag, TextTagTable) dlg;
202 		gulong handlerId;
203 		ConnectFlags flags;
204 		this(void delegate(TextTag, TextTagTable) dlg, gulong handlerId, ConnectFlags flags)
205 		{
206 			this.dlg = dlg;
207 			this.handlerId = handlerId;
208 			this.flags = flags;
209 		}
210 	}
211 	protected OnTagAddedDelegateWrapper[] onTagAddedListeners;
212 
213 	/** */
214 	gulong addOnTagAdded(void delegate(TextTag, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
215 	{
216 		onTagAddedListeners ~= new OnTagAddedDelegateWrapper(dlg, 0, connectFlags);
217 		onTagAddedListeners[onTagAddedListeners.length - 1].handlerId = Signals.connectData(
218 			this,
219 			"tag-added",
220 			cast(GCallback)&callBackTagAdded,
221 			cast(void*)onTagAddedListeners[onTagAddedListeners.length - 1],
222 			cast(GClosureNotify)&callBackTagAddedDestroy,
223 			connectFlags);
224 		return onTagAddedListeners[onTagAddedListeners.length - 1].handlerId;
225 	}
226 	
227 	extern(C) static void callBackTagAdded(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag,OnTagAddedDelegateWrapper wrapper)
228 	{
229 		wrapper.dlg(ObjectG.getDObject!(TextTag)(tag), wrapper.outer);
230 	}
231 	
232 	extern(C) static void callBackTagAddedDestroy(OnTagAddedDelegateWrapper wrapper, GClosure* closure)
233 	{
234 		wrapper.outer.internalRemoveOnTagAdded(wrapper);
235 	}
236 
237 	protected void internalRemoveOnTagAdded(OnTagAddedDelegateWrapper source)
238 	{
239 		foreach(index, wrapper; onTagAddedListeners)
240 		{
241 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
242 			{
243 				onTagAddedListeners[index] = null;
244 				onTagAddedListeners = std.algorithm.remove(onTagAddedListeners, index);
245 				break;
246 			}
247 		}
248 	}
249 	
250 
251 	protected class OnTagChangedDelegateWrapper
252 	{
253 		void delegate(TextTag, bool, TextTagTable) dlg;
254 		gulong handlerId;
255 		ConnectFlags flags;
256 		this(void delegate(TextTag, bool, TextTagTable) dlg, gulong handlerId, ConnectFlags flags)
257 		{
258 			this.dlg = dlg;
259 			this.handlerId = handlerId;
260 			this.flags = flags;
261 		}
262 	}
263 	protected OnTagChangedDelegateWrapper[] onTagChangedListeners;
264 
265 	/** */
266 	gulong addOnTagChanged(void delegate(TextTag, bool, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
267 	{
268 		onTagChangedListeners ~= new OnTagChangedDelegateWrapper(dlg, 0, connectFlags);
269 		onTagChangedListeners[onTagChangedListeners.length - 1].handlerId = Signals.connectData(
270 			this,
271 			"tag-changed",
272 			cast(GCallback)&callBackTagChanged,
273 			cast(void*)onTagChangedListeners[onTagChangedListeners.length - 1],
274 			cast(GClosureNotify)&callBackTagChangedDestroy,
275 			connectFlags);
276 		return onTagChangedListeners[onTagChangedListeners.length - 1].handlerId;
277 	}
278 	
279 	extern(C) static void callBackTagChanged(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag, bool sizeChanged,OnTagChangedDelegateWrapper wrapper)
280 	{
281 		wrapper.dlg(ObjectG.getDObject!(TextTag)(tag), sizeChanged, wrapper.outer);
282 	}
283 	
284 	extern(C) static void callBackTagChangedDestroy(OnTagChangedDelegateWrapper wrapper, GClosure* closure)
285 	{
286 		wrapper.outer.internalRemoveOnTagChanged(wrapper);
287 	}
288 
289 	protected void internalRemoveOnTagChanged(OnTagChangedDelegateWrapper source)
290 	{
291 		foreach(index, wrapper; onTagChangedListeners)
292 		{
293 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
294 			{
295 				onTagChangedListeners[index] = null;
296 				onTagChangedListeners = std.algorithm.remove(onTagChangedListeners, index);
297 				break;
298 			}
299 		}
300 	}
301 	
302 
303 	protected class OnTagRemovedDelegateWrapper
304 	{
305 		void delegate(TextTag, TextTagTable) dlg;
306 		gulong handlerId;
307 		ConnectFlags flags;
308 		this(void delegate(TextTag, TextTagTable) dlg, gulong handlerId, ConnectFlags flags)
309 		{
310 			this.dlg = dlg;
311 			this.handlerId = handlerId;
312 			this.flags = flags;
313 		}
314 	}
315 	protected OnTagRemovedDelegateWrapper[] onTagRemovedListeners;
316 
317 	/** */
318 	gulong addOnTagRemoved(void delegate(TextTag, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
319 	{
320 		onTagRemovedListeners ~= new OnTagRemovedDelegateWrapper(dlg, 0, connectFlags);
321 		onTagRemovedListeners[onTagRemovedListeners.length - 1].handlerId = Signals.connectData(
322 			this,
323 			"tag-removed",
324 			cast(GCallback)&callBackTagRemoved,
325 			cast(void*)onTagRemovedListeners[onTagRemovedListeners.length - 1],
326 			cast(GClosureNotify)&callBackTagRemovedDestroy,
327 			connectFlags);
328 		return onTagRemovedListeners[onTagRemovedListeners.length - 1].handlerId;
329 	}
330 	
331 	extern(C) static void callBackTagRemoved(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag,OnTagRemovedDelegateWrapper wrapper)
332 	{
333 		wrapper.dlg(ObjectG.getDObject!(TextTag)(tag), wrapper.outer);
334 	}
335 	
336 	extern(C) static void callBackTagRemovedDestroy(OnTagRemovedDelegateWrapper wrapper, GClosure* closure)
337 	{
338 		wrapper.outer.internalRemoveOnTagRemoved(wrapper);
339 	}
340 
341 	protected void internalRemoveOnTagRemoved(OnTagRemovedDelegateWrapper source)
342 	{
343 		foreach(index, wrapper; onTagRemovedListeners)
344 		{
345 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
346 			{
347 				onTagRemovedListeners[index] = null;
348 				onTagRemovedListeners = std.algorithm.remove(onTagRemovedListeners, index);
349 				break;
350 			}
351 		}
352 	}
353 	
354 }