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