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 private import std.algorithm;
37 
38 
39 /**
40  * The collection of tags in a `GtkTextBuffer`
41  * 
42  * You may wish to begin by reading the
43  * [text widget conceptual overview](section-text-widget.html),
44  * which gives an overview of all the objects and data types
45  * related to the text widget and how they work together.
46  * 
47  * # GtkTextTagTables as GtkBuildable
48  * 
49  * The `GtkTextTagTable` implementation of the `GtkBuildable` interface
50  * supports adding tags by specifying “tag” as the “type” attribute
51  * of a <child> element.
52  * 
53  * An example of a UI definition fragment specifying tags:
54  * ```xml
55  * <object class="GtkTextTagTable">
56  * <child type="tag">
57  * <object class="GtkTextTag"/>
58  * </child>
59  * </object>
60  * ```
61  */
62 public class TextTagTable : ObjectG, BuildableIF
63 {
64 	/** the main Gtk struct */
65 	protected GtkTextTagTable* gtkTextTagTable;
66 
67 	/** Get the main Gtk struct */
68 	public GtkTextTagTable* getTextTagTableStruct(bool transferOwnership = false)
69 	{
70 		if (transferOwnership)
71 			ownedRef = false;
72 		return gtkTextTagTable;
73 	}
74 
75 	/** the main Gtk struct as a void* */
76 	protected override void* getStruct()
77 	{
78 		return cast(void*)gtkTextTagTable;
79 	}
80 
81 	/**
82 	 * Sets our main struct and passes it to the parent class.
83 	 */
84 	public this (GtkTextTagTable* gtkTextTagTable, bool ownedRef = false)
85 	{
86 		this.gtkTextTagTable = gtkTextTagTable;
87 		super(cast(GObject*)gtkTextTagTable, ownedRef);
88 	}
89 
90 	// add the Buildable capabilities
91 	mixin BuildableT!(GtkTextTagTable);
92 
93 
94 	/** */
95 	public static GType getType()
96 	{
97 		return gtk_text_tag_table_get_type();
98 	}
99 
100 	/**
101 	 * Creates a new `GtkTextTagTable`.
102 	 *
103 	 * The table contains no tags by default.
104 	 *
105 	 * Returns: a new `GtkTextTagTable`
106 	 *
107 	 * Throws: ConstructionException GTK+ fails to create the object.
108 	 */
109 	public this()
110 	{
111 		auto __p = gtk_text_tag_table_new();
112 
113 		if(__p is null)
114 		{
115 			throw new ConstructionException("null returned by new");
116 		}
117 
118 		this(cast(GtkTextTagTable*) __p, true);
119 	}
120 
121 	/**
122 	 * Add a tag to the table.
123 	 *
124 	 * The tag is assigned the highest priority 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 	 * Returns: %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 	alias foreac = foreach_;
140 	/**
141 	 * Calls @func on each tag in @table, with user data @data.
142 	 *
143 	 * Note that the table may not be modified while iterating
144 	 * over it (you can’t add/remove tags).
145 	 *
146 	 * Params:
147 	 *     func = a function to call on each tag
148 	 *     data = user data
149 	 */
150 	public void foreach_(GtkTextTagTableForeach func, void* data)
151 	{
152 		gtk_text_tag_table_foreach(gtkTextTagTable, func, data);
153 	}
154 
155 	/**
156 	 * Returns the size of the table (number of tags)
157 	 *
158 	 * Returns: number of tags in @table
159 	 */
160 	public int getSize()
161 	{
162 		return gtk_text_tag_table_get_size(gtkTextTagTable);
163 	}
164 
165 	/**
166 	 * Look up a named tag.
167 	 *
168 	 * Params:
169 	 *     name = name of a tag
170 	 *
171 	 * Returns: The tag,
172 	 *     or %NULL if none by that name is in the table.
173 	 */
174 	public TextTag lookup(string name)
175 	{
176 		auto __p = gtk_text_tag_table_lookup(gtkTextTagTable, Str.toStringz(name));
177 
178 		if(__p is null)
179 		{
180 			return null;
181 		}
182 
183 		return ObjectG.getDObject!(TextTag)(cast(GtkTextTag*) __p);
184 	}
185 
186 	/**
187 	 * Remove a tag from the table.
188 	 *
189 	 * If a `GtkTextBuffer` has @table as its tag table, the tag is
190 	 * removed from the buffer. The table’s reference to the tag is
191 	 * removed, so the tag will end up destroyed if you don’t have
192 	 * a reference to it.
193 	 *
194 	 * Params:
195 	 *     tag = a `GtkTextTag`
196 	 */
197 	public void remove(TextTag tag)
198 	{
199 		gtk_text_tag_table_remove(gtkTextTagTable, (tag is null) ? null : tag.getTextTagStruct());
200 	}
201 
202 	/**
203 	 * Emitted every time a new tag is added in the `GtkTextTagTable`.
204 	 *
205 	 * Params:
206 	 *     tag = the added tag.
207 	 */
208 	gulong addOnTagAdded(void delegate(TextTag, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
209 	{
210 		return Signals.connect(this, "tag-added", dlg, connectFlags ^ ConnectFlags.SWAPPED);
211 	}
212 
213 	/**
214 	 * Emitted every time a tag in the `GtkTextTagTable` changes.
215 	 *
216 	 * Params:
217 	 *     tag = the changed tag.
218 	 *     sizeChanged = whether the change affects the `GtkTextView` layout.
219 	 */
220 	gulong addOnTagChanged(void delegate(TextTag, bool, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
221 	{
222 		return Signals.connect(this, "tag-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
223 	}
224 
225 	/**
226 	 * Emitted every time a tag is removed from the `GtkTextTagTable`.
227 	 *
228 	 * The @tag is still valid by the time the signal is emitted, but
229 	 * it is not associated with a tag table any more.
230 	 *
231 	 * Params:
232 	 *     tag = the removed tag.
233 	 */
234 	gulong addOnTagRemoved(void delegate(TextTag, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
235 	{
236 		return Signals.connect(this, "tag-removed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
237 	}
238 }