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 name is in the table.
170 	 */
171 	public TextTag lookup(string name)
172 	{
173 		auto p = gtk_text_tag_table_lookup(gtkTextTagTable, Str.toStringz(name));
174 		
175 		if(p is null)
176 		{
177 			return null;
178 		}
179 		
180 		return ObjectG.getDObject!(TextTag)(cast(GtkTextTag*) p);
181 	}
182 
183 	/**
184 	 * Remove a tag from the table. If a #GtkTextBuffer has @table as its tag table,
185 	 * the tag is removed from the buffer. The table’s reference to the tag is
186 	 * removed, so the tag will end up destroyed if you don’t have a reference to
187 	 * it.
188 	 *
189 	 * Params:
190 	 *     tag = a #GtkTextTag
191 	 */
192 	public void remove(TextTag tag)
193 	{
194 		gtk_text_tag_table_remove(gtkTextTagTable, (tag is null) ? null : tag.getTextTagStruct());
195 	}
196 
197 	int[string] connectedSignals;
198 
199 	void delegate(TextTag, TextTagTable)[] onTagAddedListeners;
200 	/** */
201 	void addOnTagAdded(void delegate(TextTag, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
202 	{
203 		if ( "tag-added" !in connectedSignals )
204 		{
205 			Signals.connectData(
206 				this,
207 				"tag-added",
208 				cast(GCallback)&callBackTagAdded,
209 				cast(void*)this,
210 				null,
211 				connectFlags);
212 			connectedSignals["tag-added"] = 1;
213 		}
214 		onTagAddedListeners ~= dlg;
215 	}
216 	extern(C) static void callBackTagAdded(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag, TextTagTable _texttagtable)
217 	{
218 		foreach ( void delegate(TextTag, TextTagTable) dlg; _texttagtable.onTagAddedListeners )
219 		{
220 			dlg(ObjectG.getDObject!(TextTag)(tag), _texttagtable);
221 		}
222 	}
223 
224 	void delegate(TextTag, bool, TextTagTable)[] onTagChangedListeners;
225 	/** */
226 	void addOnTagChanged(void delegate(TextTag, bool, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
227 	{
228 		if ( "tag-changed" !in connectedSignals )
229 		{
230 			Signals.connectData(
231 				this,
232 				"tag-changed",
233 				cast(GCallback)&callBackTagChanged,
234 				cast(void*)this,
235 				null,
236 				connectFlags);
237 			connectedSignals["tag-changed"] = 1;
238 		}
239 		onTagChangedListeners ~= dlg;
240 	}
241 	extern(C) static void callBackTagChanged(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag, bool sizeChanged, TextTagTable _texttagtable)
242 	{
243 		foreach ( void delegate(TextTag, bool, TextTagTable) dlg; _texttagtable.onTagChangedListeners )
244 		{
245 			dlg(ObjectG.getDObject!(TextTag)(tag), sizeChanged, _texttagtable);
246 		}
247 	}
248 
249 	void delegate(TextTag, TextTagTable)[] onTagRemovedListeners;
250 	/** */
251 	void addOnTagRemoved(void delegate(TextTag, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
252 	{
253 		if ( "tag-removed" !in connectedSignals )
254 		{
255 			Signals.connectData(
256 				this,
257 				"tag-removed",
258 				cast(GCallback)&callBackTagRemoved,
259 				cast(void*)this,
260 				null,
261 				connectFlags);
262 			connectedSignals["tag-removed"] = 1;
263 		}
264 		onTagRemovedListeners ~= dlg;
265 	}
266 	extern(C) static void callBackTagRemoved(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag, TextTagTable _texttagtable)
267 	{
268 		foreach ( void delegate(TextTag, TextTagTable) dlg; _texttagtable.onTagRemovedListeners )
269 		{
270 			dlg(ObjectG.getDObject!(TextTag)(tag), _texttagtable);
271 		}
272 	}
273 }