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.TextTag;
26 
27 private import gdk.Event;
28 private import glib.ConstructionException;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gobject.Signals;
32 private import gtk.TextIter;
33 private import gtkc.gtk;
34 public  import gtkc.gtktypes;
35 private import std.algorithm;
36 
37 
38 /**
39  * You may wish to begin by reading the
40  * [text widget conceptual overview][TextWidget]
41  * which gives an overview of all the objects and
42  * data types related to the text widget and how they work together.
43  * 
44  * Tags should be in the #GtkTextTagTable for a given #GtkTextBuffer
45  * before using them with that buffer.
46  * 
47  * gtk_text_buffer_create_tag() is the best way to create tags.
48  * See “gtk3-demo” for numerous examples.
49  * 
50  * For each property of #GtkTextTag, there is a “set” property, e.g.
51  * “font-set” corresponds to “font”. These “set” properties reflect
52  * whether a property has been set or not.
53  * They are maintained by GTK+ and you should not set them independently.
54  */
55 public class TextTag : ObjectG
56 {
57 	/** the main Gtk struct */
58 	protected GtkTextTag* gtkTextTag;
59 
60 	/** Get the main Gtk struct */
61 	public GtkTextTag* getTextTagStruct(bool transferOwnership = false)
62 	{
63 		if (transferOwnership)
64 			ownedRef = false;
65 		return gtkTextTag;
66 	}
67 
68 	/** the main Gtk struct as a void* */
69 	protected override void* getStruct()
70 	{
71 		return cast(void*)gtkTextTag;
72 	}
73 
74 	protected override void setStruct(GObject* obj)
75 	{
76 		gtkTextTag = cast(GtkTextTag*)obj;
77 		super.setStruct(obj);
78 	}
79 
80 	/**
81 	 * Sets our main struct and passes it to the parent class.
82 	 */
83 	public this (GtkTextTag* gtkTextTag, bool ownedRef = false)
84 	{
85 		this.gtkTextTag = gtkTextTag;
86 		super(cast(GObject*)gtkTextTag, ownedRef);
87 	}
88 
89 
90 	/** */
91 	public static GType getType()
92 	{
93 		return gtk_text_tag_get_type();
94 	}
95 
96 	/**
97 	 * Creates a #GtkTextTag. Configure the tag using object arguments,
98 	 * i.e. using g_object_set().
99 	 *
100 	 * Params:
101 	 *     name = tag name, or %NULL
102 	 *
103 	 * Returns: a new #GtkTextTag
104 	 *
105 	 * Throws: ConstructionException GTK+ fails to create the object.
106 	 */
107 	public this(string name)
108 	{
109 		auto p = gtk_text_tag_new(Str.toStringz(name));
110 		
111 		if(p is null)
112 		{
113 			throw new ConstructionException("null returned by new");
114 		}
115 		
116 		this(cast(GtkTextTag*) p, true);
117 	}
118 
119 	/**
120 	 * Emits the #GtkTextTagTable::tag-changed signal on the #GtkTextTagTable where
121 	 * the tag is included.
122 	 *
123 	 * The signal is already emitted when setting a #GtkTextTag property. This
124 	 * function is useful for a #GtkTextTag subclass.
125 	 *
126 	 * Params:
127 	 *     sizeChanged = whether the change affects the #GtkTextView layout.
128 	 *
129 	 * Since: 3.20
130 	 */
131 	public void changed(bool sizeChanged)
132 	{
133 		gtk_text_tag_changed(gtkTextTag, sizeChanged);
134 	}
135 
136 	/**
137 	 * Emits the “event” signal on the #GtkTextTag.
138 	 *
139 	 * Params:
140 	 *     eventObject = object that received the event, such as a widget
141 	 *     event = the event
142 	 *     iter = location where the event was received
143 	 *
144 	 * Returns: result of signal emission (whether the event was handled)
145 	 */
146 	public bool event(ObjectG eventObject, Event event, TextIter iter)
147 	{
148 		return gtk_text_tag_event(gtkTextTag, (eventObject is null) ? null : eventObject.getObjectGStruct(), (event is null) ? null : event.getEventStruct(), (iter is null) ? null : iter.getTextIterStruct()) != 0;
149 	}
150 
151 	/**
152 	 * Get the tag priority.
153 	 *
154 	 * Returns: The tag’s priority.
155 	 */
156 	public int getPriority()
157 	{
158 		return gtk_text_tag_get_priority(gtkTextTag);
159 	}
160 
161 	/**
162 	 * Sets the priority of a #GtkTextTag. Valid priorities
163 	 * start at 0 and go to one less than gtk_text_tag_table_get_size().
164 	 * Each tag in a table has a unique priority; setting the priority
165 	 * of one tag shifts the priorities of all the other tags in the
166 	 * table to maintain a unique priority for each tag. Higher priority
167 	 * tags “win” if two tags both set the same text attribute. When adding
168 	 * a tag to a tag table, it will be assigned the highest priority in
169 	 * the table by default; so normally the precedence of a set of tags
170 	 * is the order in which they were added to the table, or created with
171 	 * gtk_text_buffer_create_tag(), which adds the tag to the buffer’s table
172 	 * automatically.
173 	 *
174 	 * Params:
175 	 *     priority = the new priority
176 	 */
177 	public void setPriority(int priority)
178 	{
179 		gtk_text_tag_set_priority(gtkTextTag, priority);
180 	}
181 
182 	protected class OnDelegateWrapper
183 	{
184 		bool delegate(ObjectG, Event, TextIter, TextTag) dlg;
185 		gulong handlerId;
186 		
187 		this(bool delegate(ObjectG, Event, TextIter, TextTag) dlg)
188 		{
189 			this.dlg = dlg;
190 			onListeners ~= this;
191 		}
192 		
193 		void remove(OnDelegateWrapper source)
194 		{
195 			foreach(index, wrapper; onListeners)
196 			{
197 				if (wrapper.handlerId == source.handlerId)
198 				{
199 					onListeners[index] = null;
200 					onListeners = std.algorithm.remove(onListeners, index);
201 					break;
202 				}
203 			}
204 		}
205 	}
206 	OnDelegateWrapper[] onListeners;
207 
208 	/**
209 	 * The ::event signal is emitted when an event occurs on a region of the
210 	 * buffer marked with this tag.
211 	 *
212 	 * Params:
213 	 *     object = the object the event was fired from (typically a #GtkTextView)
214 	 *     event = the event which triggered the signal
215 	 *     iter = a #GtkTextIter pointing at the location the event occurred
216 	 *
217 	 * Returns: %TRUE to stop other handlers from being invoked for the
218 	 *     event. %FALSE to propagate the event further.
219 	 */
220 	gulong addOn(bool delegate(ObjectG, Event, TextIter, TextTag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
221 	{
222 		auto wrapper = new OnDelegateWrapper(dlg);
223 		wrapper.handlerId = Signals.connectData(
224 			this,
225 			"event",
226 			cast(GCallback)&callBack,
227 			cast(void*)wrapper,
228 			cast(GClosureNotify)&callBackDestroy,
229 			connectFlags);
230 		return wrapper.handlerId;
231 	}
232 	
233 	extern(C) static int callBack(GtkTextTag* texttagStruct, GObject* object, GdkEvent* event, GtkTextIter* iter, OnDelegateWrapper wrapper)
234 	{
235 		return wrapper.dlg(ObjectG.getDObject!(ObjectG)(object), ObjectG.getDObject!(Event)(event), ObjectG.getDObject!(TextIter)(iter), wrapper.outer);
236 	}
237 	
238 	extern(C) static void callBackDestroy(OnDelegateWrapper wrapper, GClosure* closure)
239 	{
240 		wrapper.remove(wrapper);
241 	}
242 }