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 
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 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 	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 	void addOnTagChanged(void delegate(TextTag, bool, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
226 	{
227 		if ( "tag-changed" !in connectedSignals )
228 		{
229 			Signals.connectData(
230 				this,
231 				"tag-changed",
232 				cast(GCallback)&callBackTagChanged,
233 				cast(void*)this,
234 				null,
235 				connectFlags);
236 			connectedSignals["tag-changed"] = 1;
237 		}
238 		onTagChangedListeners ~= dlg;
239 	}
240 	extern(C) static void callBackTagChanged(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag, bool sizeChanged, TextTagTable _texttagtable)
241 	{
242 		foreach ( void delegate(TextTag, bool, TextTagTable) dlg; _texttagtable.onTagChangedListeners )
243 		{
244 			dlg(ObjectG.getDObject!(TextTag)(tag), sizeChanged, _texttagtable);
245 		}
246 	}
247 
248 	void delegate(TextTag, TextTagTable)[] onTagRemovedListeners;
249 	void addOnTagRemoved(void delegate(TextTag, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
250 	{
251 		if ( "tag-removed" !in connectedSignals )
252 		{
253 			Signals.connectData(
254 				this,
255 				"tag-removed",
256 				cast(GCallback)&callBackTagRemoved,
257 				cast(void*)this,
258 				null,
259 				connectFlags);
260 			connectedSignals["tag-removed"] = 1;
261 		}
262 		onTagRemovedListeners ~= dlg;
263 	}
264 	extern(C) static void callBackTagRemoved(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag, TextTagTable _texttagtable)
265 	{
266 		foreach ( void delegate(TextTag, TextTagTable) dlg; _texttagtable.onTagRemovedListeners )
267 		{
268 			dlg(ObjectG.getDObject!(TextTag)(tag), _texttagtable);
269 		}
270 	}
271 }