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.Str;
29 private import gobject.ObjectG;
30 private import gtkc.gtk;
31 public  import gtkc.gtktypes;
32 
33 
34 /**
35  * A binding set maintains a list of activatable key bindings.
36  * A single binding set can match multiple types of widgets.
37  * Similar to style contexts, can be matched by any information contained
38  * in a widgets #GtkWidgetPath. When a binding within a set is matched upon
39  * activation, an action signal is emitted on the target widget to carry out
40  * the actual activation.
41  */
42 public class BindingSet
43 {
44 	/** the main Gtk struct */
45 	protected GtkBindingSet* gtkBindingSet;
46 	protected bool ownedRef;
47 
48 	/** Get the main Gtk struct */
49 	public GtkBindingSet* getBindingSetStruct(bool transferOwnership = false)
50 	{
51 		if (transferOwnership)
52 			ownedRef = false;
53 		return gtkBindingSet;
54 	}
55 
56 	/** the main Gtk struct as a void* */
57 	protected void* getStruct()
58 	{
59 		return cast(void*)gtkBindingSet;
60 	}
61 
62 	/**
63 	 * Sets our main struct and passes it to the parent class.
64 	 */
65 	public this (GtkBindingSet* gtkBindingSet, bool ownedRef = false)
66 	{
67 		this.gtkBindingSet = gtkBindingSet;
68 		this.ownedRef = ownedRef;
69 	}
70 
71 
72 	/**
73 	 * Find a key binding matching @keyval and @modifiers within
74 	 * @binding_set and activate the binding on @object.
75 	 *
76 	 * Params:
77 	 *     keyval = key value of the binding
78 	 *     modifiers = key modifier of the binding
79 	 *     object = object to activate when binding found
80 	 *
81 	 * Returns: %TRUE if a binding was found and activated
82 	 */
83 	public bool activate(uint keyval, GdkModifierType modifiers, ObjectG object)
84 	{
85 		return gtk_binding_set_activate(gtkBindingSet, keyval, modifiers, (object is null) ? null : object.getObjectGStruct()) != 0;
86 	}
87 
88 	/**
89 	 * This function was used internally by the GtkRC parsing mechanism
90 	 * to assign match patterns to #GtkBindingSet structures.
91 	 *
92 	 * In GTK+ 3, these match patterns are unused.
93 	 *
94 	 * Params:
95 	 *     pathType = path type the pattern applies to
96 	 *     pathPattern = the actual match pattern
97 	 *     priority = binding priority
98 	 */
99 	public void addPath(GtkPathType pathType, string pathPattern, GtkPathPriorityType priority)
100 	{
101 		gtk_binding_set_add_path(gtkBindingSet, pathType, Str.toStringz(pathPattern), priority);
102 	}
103 
104 	/**
105 	 * This function returns the binding set named after the type name of
106 	 * the passed in class structure. New binding sets are created on
107 	 * demand by this function.
108 	 *
109 	 * Params:
110 	 *     objectClass = a valid #GObject class
111 	 *
112 	 * Returns: the binding set corresponding to
113 	 *     @object_class
114 	 */
115 	public static BindingSet byClass(void* objectClass)
116 	{
117 		auto p = gtk_binding_set_by_class(objectClass);
118 		
119 		if(p is null)
120 		{
121 			return null;
122 		}
123 		
124 		return ObjectG.getDObject!(BindingSet)(cast(GtkBindingSet*) p);
125 	}
126 
127 	/**
128 	 * Find a binding set by its globally unique name.
129 	 *
130 	 * The @set_name can either be a name used for gtk_binding_set_new()
131 	 * or the type name of a class used in gtk_binding_set_by_class().
132 	 *
133 	 * Params:
134 	 *     setName = unique binding set name
135 	 *
136 	 * Returns: %NULL or the specified binding set
137 	 */
138 	public static BindingSet find(string setName)
139 	{
140 		auto p = gtk_binding_set_find(Str.toStringz(setName));
141 		
142 		if(p is null)
143 		{
144 			return null;
145 		}
146 		
147 		return ObjectG.getDObject!(BindingSet)(cast(GtkBindingSet*) p);
148 	}
149 
150 	/**
151 	 * GTK+ maintains a global list of binding sets. Each binding set has
152 	 * a unique name which needs to be specified upon creation.
153 	 *
154 	 * Params:
155 	 *     setName = unique name of this binding set
156 	 *
157 	 * Returns: new binding set
158 	 *
159 	 * Throws: ConstructionException GTK+ fails to create the object.
160 	 */
161 	public this(string setName)
162 	{
163 		auto p = gtk_binding_set_new(Str.toStringz(setName));
164 		
165 		if(p is null)
166 		{
167 			throw new ConstructionException("null returned by new");
168 		}
169 		
170 		this(cast(GtkBindingSet*) p);
171 	}
172 
173 	/**
174 	 * Find a key binding matching @keyval and @modifiers and activate the
175 	 * binding on @object.
176 	 *
177 	 * Params:
178 	 *     object = object to activate when binding found
179 	 *     keyval = key value of the binding
180 	 *     modifiers = key modifier of the binding
181 	 *
182 	 * Returns: %TRUE if a binding was found and activated
183 	 */
184 	public static bool bindingsActivate(ObjectG object, uint keyval, GdkModifierType modifiers)
185 	{
186 		return gtk_bindings_activate((object is null) ? null : object.getObjectGStruct(), keyval, modifiers) != 0;
187 	}
188 
189 	/**
190 	 * Looks up key bindings for @object to find one matching
191 	 * @event, and if one was found, activate it.
192 	 *
193 	 * Params:
194 	 *     object = a #GObject (generally must be a widget)
195 	 *     event = a #GdkEventKey
196 	 *
197 	 * Returns: %TRUE if a matching key binding was found
198 	 *
199 	 * Since: 2.4
200 	 */
201 	public static bool bindingsActivateEvent(ObjectG object, GdkEventKey* event)
202 	{
203 		return gtk_bindings_activate_event((object is null) ? null : object.getObjectGStruct(), event) != 0;
204 	}
205 }