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.BindingSet;
26 
27 private import glib.ConstructionException;
28 private import glib.ListSG;
29 private import glib.Str;
30 private import glib.c.functions;
31 private import gobject.ObjectG;
32 private import gtk.c.functions;
33 public  import gtk.c.types;
34 public  import gtkc.gtktypes;
35 private import gtkd.Loader;
36 
37 
38 /**
39  * A binding set maintains a list of activatable key bindings.
40  * A single binding set can match multiple types of widgets.
41  * Similar to style contexts, can be matched by any information contained
42  * in a widgets #GtkWidgetPath. When a binding within a set is matched upon
43  * activation, an action signal is emitted on the target widget to carry out
44  * the actual activation.
45  */
46 public final class BindingSet
47 {
48 	/** the main Gtk struct */
49 	protected GtkBindingSet* gtkBindingSet;
50 	protected bool ownedRef;
51 
52 	/** Get the main Gtk struct */
53 	public GtkBindingSet* getBindingSetStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return gtkBindingSet;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected void* getStruct()
62 	{
63 		return cast(void*)gtkBindingSet;
64 	}
65 
66 	/**
67 	 * Sets our main struct and passes it to the parent class.
68 	 */
69 	public this (GtkBindingSet* gtkBindingSet, bool ownedRef = false)
70 	{
71 		this.gtkBindingSet = gtkBindingSet;
72 		this.ownedRef = ownedRef;
73 	}
74 
75 	~this ()
76 	{
77 		if ( Linker.isLoaded(LIBRARY_GTK) && ownedRef )
78 			g_free(gtkBindingSet);
79 	}
80 
81 
82 	/**
83 	 * unique name of this binding set
84 	 */
85 	public @property string setName()
86 	{
87 		return Str.toString(gtkBindingSet.setName);
88 	}
89 
90 	/** Ditto */
91 	public @property void setName(string value)
92 	{
93 		gtkBindingSet.setName = Str.toStringz(value);
94 	}
95 
96 	/**
97 	 * unused
98 	 */
99 	public @property int priority()
100 	{
101 		return gtkBindingSet.priority;
102 	}
103 
104 	/** Ditto */
105 	public @property void priority(int value)
106 	{
107 		gtkBindingSet.priority = value;
108 	}
109 
110 	/**
111 	 * unused
112 	 */
113 	public @property ListSG widgetPathPspecs()
114 	{
115 		return new ListSG(gtkBindingSet.widgetPathPspecs, false);
116 	}
117 
118 	/** Ditto */
119 	public @property void widgetPathPspecs(ListSG value)
120 	{
121 		gtkBindingSet.widgetPathPspecs = value.getListSGStruct();
122 	}
123 
124 	/**
125 	 * unused
126 	 */
127 	public @property ListSG widgetClassPspecs()
128 	{
129 		return new ListSG(gtkBindingSet.widgetClassPspecs, false);
130 	}
131 
132 	/** Ditto */
133 	public @property void widgetClassPspecs(ListSG value)
134 	{
135 		gtkBindingSet.widgetClassPspecs = value.getListSGStruct();
136 	}
137 
138 	/**
139 	 * unused
140 	 */
141 	public @property ListSG classBranchPspecs()
142 	{
143 		return new ListSG(gtkBindingSet.classBranchPspecs, false);
144 	}
145 
146 	/** Ditto */
147 	public @property void classBranchPspecs(ListSG value)
148 	{
149 		gtkBindingSet.classBranchPspecs = value.getListSGStruct();
150 	}
151 
152 	/**
153 	 * the key binding entries in this binding set
154 	 */
155 	public @property GtkBindingEntry* entries()
156 	{
157 		return gtkBindingSet.entries;
158 	}
159 
160 	/** Ditto */
161 	public @property void entries(GtkBindingEntry* value)
162 	{
163 		gtkBindingSet.entries = value;
164 	}
165 
166 	/**
167 	 * implementation detail
168 	 */
169 	public @property GtkBindingEntry* current()
170 	{
171 		return gtkBindingSet.current;
172 	}
173 
174 	/** Ditto */
175 	public @property void current(GtkBindingEntry* value)
176 	{
177 		gtkBindingSet.current = value;
178 	}
179 
180 	/**
181 	 * whether this binding set stems from a CSS file and is reset upon theme changes
182 	 */
183 	public @property uint parsed()
184 	{
185 		return gtkBindingSet.parsed;
186 	}
187 
188 	/** Ditto */
189 	public @property void parsed(uint value)
190 	{
191 		gtkBindingSet.parsed = value;
192 	}
193 
194 	/**
195 	 * Find a key binding matching @keyval and @modifiers within
196 	 * @binding_set and activate the binding on @object.
197 	 *
198 	 * Params:
199 	 *     keyval = key value of the binding
200 	 *     modifiers = key modifier of the binding
201 	 *     object = object to activate when binding found
202 	 *
203 	 * Returns: %TRUE if a binding was found and activated
204 	 */
205 	public bool activate(uint keyval, GdkModifierType modifiers, ObjectG object)
206 	{
207 		return gtk_binding_set_activate(gtkBindingSet, keyval, modifiers, (object is null) ? null : object.getObjectGStruct()) != 0;
208 	}
209 
210 	/**
211 	 * This function was used internally by the GtkRC parsing mechanism
212 	 * to assign match patterns to #GtkBindingSet structures.
213 	 *
214 	 * In GTK+ 3, these match patterns are unused.
215 	 *
216 	 * Params:
217 	 *     pathType = path type the pattern applies to
218 	 *     pathPattern = the actual match pattern
219 	 *     priority = binding priority
220 	 */
221 	public void addPath(GtkPathType pathType, string pathPattern, GtkPathPriorityType priority)
222 	{
223 		gtk_binding_set_add_path(gtkBindingSet, pathType, Str.toStringz(pathPattern), priority);
224 	}
225 
226 	/**
227 	 * This function returns the binding set named after the type name of
228 	 * the passed in class structure. New binding sets are created on
229 	 * demand by this function.
230 	 *
231 	 * Params:
232 	 *     objectClass = a valid #GObject class
233 	 *
234 	 * Returns: the binding set corresponding to
235 	 *     @object_class
236 	 */
237 	public static BindingSet byClass(void* objectClass)
238 	{
239 		auto p = gtk_binding_set_by_class(objectClass);
240 
241 		if(p is null)
242 		{
243 			return null;
244 		}
245 
246 		return ObjectG.getDObject!(BindingSet)(cast(GtkBindingSet*) p);
247 	}
248 
249 	/**
250 	 * Find a binding set by its globally unique name.
251 	 *
252 	 * The @set_name can either be a name used for gtk_binding_set_new()
253 	 * or the type name of a class used in gtk_binding_set_by_class().
254 	 *
255 	 * Params:
256 	 *     setName = unique binding set name
257 	 *
258 	 * Returns: %NULL or the specified binding set
259 	 */
260 	public static BindingSet find(string setName)
261 	{
262 		auto p = gtk_binding_set_find(Str.toStringz(setName));
263 
264 		if(p is null)
265 		{
266 			return null;
267 		}
268 
269 		return ObjectG.getDObject!(BindingSet)(cast(GtkBindingSet*) p);
270 	}
271 
272 	/**
273 	 * GTK+ maintains a global list of binding sets. Each binding set has
274 	 * a unique name which needs to be specified upon creation.
275 	 *
276 	 * Params:
277 	 *     setName = unique name of this binding set
278 	 *
279 	 * Returns: new binding set
280 	 *
281 	 * Throws: ConstructionException GTK+ fails to create the object.
282 	 */
283 	public this(string setName)
284 	{
285 		auto p = gtk_binding_set_new(Str.toStringz(setName));
286 
287 		if(p is null)
288 		{
289 			throw new ConstructionException("null returned by new");
290 		}
291 
292 		this(cast(GtkBindingSet*) p);
293 	}
294 
295 	/**
296 	 * Find a key binding matching @keyval and @modifiers and activate the
297 	 * binding on @object.
298 	 *
299 	 * Params:
300 	 *     object = object to activate when binding found
301 	 *     keyval = key value of the binding
302 	 *     modifiers = key modifier of the binding
303 	 *
304 	 * Returns: %TRUE if a binding was found and activated
305 	 */
306 	public static bool bindingsActivate(ObjectG object, uint keyval, GdkModifierType modifiers)
307 	{
308 		return gtk_bindings_activate((object is null) ? null : object.getObjectGStruct(), keyval, modifiers) != 0;
309 	}
310 
311 	/**
312 	 * Looks up key bindings for @object to find one matching
313 	 * @event, and if one was found, activate it.
314 	 *
315 	 * Params:
316 	 *     object = a #GObject (generally must be a widget)
317 	 *     event = a #GdkEventKey
318 	 *
319 	 * Returns: %TRUE if a matching key binding was found
320 	 *
321 	 * Since: 2.4
322 	 */
323 	public static bool bindingsActivateEvent(ObjectG object, GdkEventKey* event)
324 	{
325 		return gtk_bindings_activate_event((object is null) ? null : object.getObjectGStruct(), event) != 0;
326 	}
327 }