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