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 
38 
39 /**
40  * You may wish to begin by reading the
41  * [text widget conceptual overview][TextWidget]
42  * which gives an overview of all the objects and
43  * data types related to the text widget and how they work together.
44  * 
45  * # GtkTextTagTables as GtkBuildable
46  * 
47  * The GtkTextTagTable implementation of the GtkBuildable interface
48  * supports adding tags by specifying “tag” as the “type” attribute
49  * of a <child> element.
50  * 
51  * An example of a UI definition fragment specifying tags:
52  * |[
53  * <object class="GtkTextTagTable">
54  * <child type="tag">
55  * <object class="GtkTextTag"/>
56  * </child>
57  * </object>
58  * ]|
59  */
60 public class TextTagTable : ObjectG, BuildableIF
61 {
62 	/** the main Gtk struct */
63 	protected GtkTextTagTable* gtkTextTagTable;
64 
65 	/** Get the main Gtk struct */
66 	public GtkTextTagTable* getTextTagTableStruct()
67 	{
68 		return gtkTextTagTable;
69 	}
70 
71 	/** the main Gtk struct as a void* */
72 	protected override void* getStruct()
73 	{
74 		return cast(void*)gtkTextTagTable;
75 	}
76 
77 	protected override void setStruct(GObject* obj)
78 	{
79 		gtkTextTagTable = cast(GtkTextTagTable*)obj;
80 		super.setStruct(obj);
81 	}
82 
83 	/**
84 	 * Sets our main struct and passes it to the parent class.
85 	 */
86 	public this (GtkTextTagTable* gtkTextTagTable, bool ownedRef = false)
87 	{
88 		this.gtkTextTagTable = gtkTextTagTable;
89 		super(cast(GObject*)gtkTextTagTable, ownedRef);
90 	}
91 
92 	// add the Buildable capabilities
93 	mixin BuildableT!(GtkTextTagTable);
94 
95 
96 	/** */
97 	public static GType getType()
98 	{
99 		return gtk_text_tag_table_get_type();
100 	}
101 
102 	/**
103 	 * Creates a new #GtkTextTagTable. The table contains no tags by
104 	 * default.
105 	 *
106 	 * Return: a new #GtkTextTagTable
107 	 *
108 	 * Throws: ConstructionException GTK+ fails to create the object.
109 	 */
110 	public this()
111 	{
112 		auto p = gtk_text_tag_table_new();
113 		
114 		if(p is null)
115 		{
116 			throw new ConstructionException("null returned by new");
117 		}
118 		
119 		this(cast(GtkTextTagTable*) p, true);
120 	}
121 
122 	/**
123 	 * Add a tag to the table. The tag is assigned the highest priority
124 	 * in the table.
125 	 *
126 	 * @tag must not be in a tag table already, and may not have
127 	 * the same name as an already-added tag.
128 	 *
129 	 * Params:
130 	 *     tag = a #GtkTextTag
131 	 *
132 	 * Return: %TRUE on success.
133 	 */
134 	public bool add(TextTag tag)
135 	{
136 		return gtk_text_tag_table_add(gtkTextTagTable, (tag is null) ? null : tag.getTextTagStruct()) != 0;
137 	}
138 
139 	/**
140 	 * Calls @func on each tag in @table, with user data @data.
141 	 * Note that the table may not be modified while iterating
142 	 * over it (you can’t add/remove tags).
143 	 *
144 	 * Params:
145 	 *     func = a function to call on each tag
146 	 *     data = user data
147 	 */
148 	public void foreac(GtkTextTagTableForeach func, void* data)
149 	{
150 		gtk_text_tag_table_foreach(gtkTextTagTable, func, data);
151 	}
152 
153 	/**
154 	 * Returns the size of the table (number of tags)
155 	 *
156 	 * Return: number of tags in @table
157 	 */
158 	public int getSize()
159 	{
160 		return gtk_text_tag_table_get_size(gtkTextTagTable);
161 	}
162 
163 	/**
164 	 * Look up a named tag.
165 	 *
166 	 * Params:
167 	 *     name = name of a tag
168 	 *
169 	 * Return: The tag, or %NULL if none by that
170 	 *     name is in the table.
171 	 */
172 	public TextTag lookup(string name)
173 	{
174 		auto p = gtk_text_tag_table_lookup(gtkTextTagTable, Str.toStringz(name));
175 		
176 		if(p is null)
177 		{
178 			return null;
179 		}
180 		
181 		return ObjectG.getDObject!(TextTag)(cast(GtkTextTag*) p);
182 	}
183 
184 	/**
185 	 * Remove a tag from the table. If a #GtkTextBuffer has @table as its tag table,
186 	 * the tag is removed from the buffer. The table’s reference to the tag is
187 	 * removed, so the tag will end up destroyed if you don’t have a reference to
188 	 * it.
189 	 *
190 	 * Params:
191 	 *     tag = a #GtkTextTag
192 	 */
193 	public void remove(TextTag tag)
194 	{
195 		gtk_text_tag_table_remove(gtkTextTagTable, (tag is null) ? null : tag.getTextTagStruct());
196 	}
197 
198 	int[string] connectedSignals;
199 
200 	void delegate(TextTag, TextTagTable)[] onTagAddedListeners;
201 	/** */
202 	void addOnTagAdded(void delegate(TextTag, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
203 	{
204 		if ( "tag-added" !in connectedSignals )
205 		{
206 			Signals.connectData(
207 				this,
208 				"tag-added",
209 				cast(GCallback)&callBackTagAdded,
210 				cast(void*)this,
211 				null,
212 				connectFlags);
213 			connectedSignals["tag-added"] = 1;
214 		}
215 		onTagAddedListeners ~= dlg;
216 	}
217 	extern(C) static void callBackTagAdded(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag, TextTagTable _texttagtable)
218 	{
219 		foreach ( void delegate(TextTag, TextTagTable) dlg; _texttagtable.onTagAddedListeners )
220 		{
221 			dlg(ObjectG.getDObject!(TextTag)(tag), _texttagtable);
222 		}
223 	}
224 
225 	void delegate(TextTag, bool, TextTagTable)[] onTagChangedListeners;
226 	/** */
227 	void addOnTagChanged(void delegate(TextTag, bool, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
228 	{
229 		if ( "tag-changed" !in connectedSignals )
230 		{
231 			Signals.connectData(
232 				this,
233 				"tag-changed",
234 				cast(GCallback)&callBackTagChanged,
235 				cast(void*)this,
236 				null,
237 				connectFlags);
238 			connectedSignals["tag-changed"] = 1;
239 		}
240 		onTagChangedListeners ~= dlg;
241 	}
242 	extern(C) static void callBackTagChanged(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag, bool sizeChanged, TextTagTable _texttagtable)
243 	{
244 		foreach ( void delegate(TextTag, bool, TextTagTable) dlg; _texttagtable.onTagChangedListeners )
245 		{
246 			dlg(ObjectG.getDObject!(TextTag)(tag), sizeChanged, _texttagtable);
247 		}
248 	}
249 
250 	void delegate(TextTag, TextTagTable)[] onTagRemovedListeners;
251 	/** */
252 	void addOnTagRemoved(void delegate(TextTag, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
253 	{
254 		if ( "tag-removed" !in connectedSignals )
255 		{
256 			Signals.connectData(
257 				this,
258 				"tag-removed",
259 				cast(GCallback)&callBackTagRemoved,
260 				cast(void*)this,
261 				null,
262 				connectFlags);
263 			connectedSignals["tag-removed"] = 1;
264 		}
265 		onTagRemovedListeners ~= dlg;
266 	}
267 	extern(C) static void callBackTagRemoved(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag, TextTagTable _texttagtable)
268 	{
269 		foreach ( void delegate(TextTag, TextTagTable) dlg; _texttagtable.onTagRemovedListeners )
270 		{
271 			dlg(ObjectG.getDObject!(TextTag)(tag), _texttagtable);
272 		}
273 	}
274 }