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