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  * Conversion parameters:
26  * inFile  = gtk-Keyboard-Accelerators.html
27  * outPack = gtk
28  * outFile = AccelGroup
29  * strct   = GtkAccelGroup
30  * realStrct=
31  * ctorStrct=
32  * clss    = AccelGroup
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_accel_group_
41  * 	- gtk_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- gobject.Closure
49  * 	- gobject.ObjectG
50  * 	- gtk.AccelGroup
51  * 	- glib.ListSG
52  * structWrap:
53  * 	- GClosure* -> Closure
54  * 	- GObject* -> ObjectG
55  * 	- GSList* -> ListSG
56  * 	- GtkAccelGroup* -> AccelGroup
57  * module aliases:
58  * local aliases:
59  * overrides:
60  */
61 
62 module gtk.AccelGroup;
63 
64 public  import gtkc.gtktypes;
65 
66 private import gtkc.gtk;
67 private import glib.ConstructionException;
68 private import gobject.ObjectG;
69 
70 private import gobject.Signals;
71 public  import gtkc.gdktypes;
72 
73 private import glib.Str;
74 private import gobject.Closure;
75 private import gobject.ObjectG;
76 private import gtk.AccelGroup;
77 private import glib.ListSG;
78 
79 
80 
81 private import gobject.ObjectG;
82 
83 /**
84  * Description
85  * A GtkAccelGroup represents a group of keyboard accelerators,
86  * typically attached to a toplevel GtkWindow (with
87  * gtk_window_add_accel_group()). Usually you won't need to create a
88  * GtkAccelGroup directly; instead, when using GtkItemFactory, GTK+
89  * automatically sets up the accelerators for your menus in the item
90  * factory's GtkAccelGroup.
91  * Note that accelerators are different from
92  * mnemonics. Accelerators are shortcuts for
93  * activating a menu item; they appear alongside the menu item they're a
94  * shortcut for. For example "Ctrl+Q" might appear alongside the "Quit"
95  * menu item. Mnemonics are shortcuts for GUI elements such as text
96  * entries or buttons; they appear as underlined characters. See
97  * gtk_label_new_with_mnemonic(). Menu items can have both accelerators
98  * and mnemonics, of course.
99  */
100 public class AccelGroup : ObjectG
101 {
102 	
103 	/** the main Gtk struct */
104 	protected GtkAccelGroup* gtkAccelGroup;
105 	
106 	
107 	public GtkAccelGroup* getAccelGroupStruct()
108 	{
109 		return gtkAccelGroup;
110 	}
111 	
112 	
113 	/** the main Gtk struct as a void* */
114 	protected override void* getStruct()
115 	{
116 		return cast(void*)gtkAccelGroup;
117 	}
118 	
119 	/**
120 	 * Sets our main struct and passes it to the parent class
121 	 */
122 	public this (GtkAccelGroup* gtkAccelGroup)
123 	{
124 		super(cast(GObject*)gtkAccelGroup);
125 		this.gtkAccelGroup = gtkAccelGroup;
126 	}
127 	
128 	protected override void setStruct(GObject* obj)
129 	{
130 		super.setStruct(obj);
131 		gtkAccelGroup = cast(GtkAccelGroup*)obj;
132 	}
133 	
134 	/**
135 	 */
136 	int[string] connectedSignals;
137 	
138 	bool delegate(ObjectG, guint, GdkModifierType, AccelGroup)[] onAccelActivateListeners;
139 	/**
140 	 * The accel-activate signal is an implementation detail of
141 	 * GtkAccelGroup and not meant to be used by applications.
142 	 * TRUE if the accelerator was activated
143 	 */
144 	void addOnAccelActivate(bool delegate(ObjectG, guint, GdkModifierType, AccelGroup) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
145 	{
146 		if ( !("accel-activate" in connectedSignals) )
147 		{
148 			Signals.connectData(
149 			getStruct(),
150 			"accel-activate",
151 			cast(GCallback)&callBackAccelActivate,
152 			cast(void*)this,
153 			null,
154 			connectFlags);
155 			connectedSignals["accel-activate"] = 1;
156 		}
157 		onAccelActivateListeners ~= dlg;
158 	}
159 	extern(C) static gboolean callBackAccelActivate(GtkAccelGroup* accelGroupStruct, GObject* acceleratable, guint keyval, GdkModifierType modifier, AccelGroup _accelGroup)
160 	{
161 		foreach ( bool delegate(ObjectG, guint, GdkModifierType, AccelGroup) dlg ; _accelGroup.onAccelActivateListeners )
162 		{
163 			if ( dlg(ObjectG.getDObject!(ObjectG)(acceleratable), keyval, modifier, _accelGroup) )
164 			{
165 				return 1;
166 			}
167 		}
168 		
169 		return 0;
170 	}
171 	
172 	void delegate(guint, GdkModifierType, Closure, AccelGroup)[] onAccelChangedListeners;
173 	/**
174 	 * The accel-changed signal is emitted when a GtkAccelGroupEntry
175 	 * is added to or removed from the accel group.
176 	 * Widgets like GtkAccelLabel which display an associated
177 	 * accelerator should connect to this signal, and rebuild
178 	 * their visual representation if the accel_closure is theirs.
179 	 * See Also
180 	 * gtk_window_add_accel_group(), gtk_accel_map_change_entry(),
181 	 * gtk_item_factory_new(), gtk_label_new_with_mnemonic()
182 	 */
183 	void addOnAccelChanged(void delegate(guint, GdkModifierType, Closure, AccelGroup) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
184 	{
185 		if ( !("accel-changed" in connectedSignals) )
186 		{
187 			Signals.connectData(
188 			getStruct(),
189 			"accel-changed",
190 			cast(GCallback)&callBackAccelChanged,
191 			cast(void*)this,
192 			null,
193 			connectFlags);
194 			connectedSignals["accel-changed"] = 1;
195 		}
196 		onAccelChangedListeners ~= dlg;
197 	}
198 	extern(C) static void callBackAccelChanged(GtkAccelGroup* accelGroupStruct, guint keyval, GdkModifierType modifier, GClosure* accelClosure, AccelGroup _accelGroup)
199 	{
200 		foreach ( void delegate(guint, GdkModifierType, Closure, AccelGroup) dlg ; _accelGroup.onAccelChangedListeners )
201 		{
202 			dlg(keyval, modifier, ObjectG.getDObject!(Closure)(accelClosure), _accelGroup);
203 		}
204 	}
205 	
206 	
207 	/**
208 	 * Creates a new GtkAccelGroup.
209 	 * Throws: ConstructionException GTK+ fails to create the object.
210 	 */
211 	public this ()
212 	{
213 		// GtkAccelGroup * gtk_accel_group_new (void);
214 		auto p = gtk_accel_group_new();
215 		if(p is null)
216 		{
217 			throw new ConstructionException("null returned by gtk_accel_group_new()");
218 		}
219 		this(cast(GtkAccelGroup*) p);
220 	}
221 	
222 	/**
223 	 * Installs an accelerator in this group. When accel_group is being activated
224 	 * in response to a call to gtk_accel_groups_activate(), closure will be
225 	 * invoked if the accel_key and accel_mods from gtk_accel_groups_activate()
226 	 * match those of this connection.
227 	 * The signature used for the closure is that of GtkAccelGroupActivate.
228 	 * Note that, due to implementation details, a single closure can only be
229 	 * connected to one accelerator group.
230 	 * Params:
231 	 * accelKey = key value of the accelerator
232 	 * accelMods = modifier combination of the accelerator
233 	 * accelFlags = a flag mask to configure this accelerator
234 	 * closure = closure to be executed upon accelerator activation
235 	 */
236 	public void connect(uint accelKey, GdkModifierType accelMods, GtkAccelFlags accelFlags, Closure closure)
237 	{
238 		// void gtk_accel_group_connect (GtkAccelGroup *accel_group,  guint accel_key,  GdkModifierType accel_mods,  GtkAccelFlags accel_flags,  GClosure *closure);
239 		gtk_accel_group_connect(gtkAccelGroup, accelKey, accelMods, accelFlags, (closure is null) ? null : closure.getClosureStruct());
240 	}
241 	
242 	/**
243 	 * Installs an accelerator in this group, using an accelerator path to look
244 	 * up the appropriate key and modifiers (see gtk_accel_map_add_entry()).
245 	 * When accel_group is being activated in response to a call to
246 	 * gtk_accel_groups_activate(), closure will be invoked if the accel_key and
247 	 * accel_mods from gtk_accel_groups_activate() match the key and modifiers
248 	 * for the path.
249 	 * The signature used for the closure is that of GtkAccelGroupActivate.
250 	 * Note that accel_path string will be stored in a GQuark. Therefore, if you
251 	 * pass a static string, you can save some memory by interning it first with
252 	 * g_intern_static_string().
253 	 * Params:
254 	 * accelPath = path used for determining key and modifiers.
255 	 * closure = closure to be executed upon accelerator activation
256 	 */
257 	public void connectByPath(string accelPath, Closure closure)
258 	{
259 		// void gtk_accel_group_connect_by_path (GtkAccelGroup *accel_group,  const gchar *accel_path,  GClosure *closure);
260 		gtk_accel_group_connect_by_path(gtkAccelGroup, Str.toStringz(accelPath), (closure is null) ? null : closure.getClosureStruct());
261 	}
262 	
263 	/**
264 	 * Removes an accelerator previously installed through
265 	 * gtk_accel_group_connect().
266 	 * Since 2.20 closure can be NULL.
267 	 * Params:
268 	 * closure = the closure to remove from this accelerator group, or NULL
269 	 * to remove all closures. [allow-none]
270 	 * Returns: TRUE if the closure was found and got disconnected
271 	 */
272 	public int disconnect(Closure closure)
273 	{
274 		// gboolean gtk_accel_group_disconnect (GtkAccelGroup *accel_group,  GClosure *closure);
275 		return gtk_accel_group_disconnect(gtkAccelGroup, (closure is null) ? null : closure.getClosureStruct());
276 	}
277 	
278 	/**
279 	 * Removes an accelerator previously installed through
280 	 * gtk_accel_group_connect().
281 	 * Params:
282 	 * accelKey = key value of the accelerator
283 	 * accelMods = modifier combination of the accelerator
284 	 * Returns: TRUE if there was an accelerator which could be removed, FALSE otherwise
285 	 */
286 	public int disconnectKey(uint accelKey, GdkModifierType accelMods)
287 	{
288 		// gboolean gtk_accel_group_disconnect_key (GtkAccelGroup *accel_group,  guint accel_key,  GdkModifierType accel_mods);
289 		return gtk_accel_group_disconnect_key(gtkAccelGroup, accelKey, accelMods);
290 	}
291 	
292 	/**
293 	 * Queries an accelerator group for all entries matching accel_key and
294 	 * accel_mods.
295 	 * Params:
296 	 * accelKey = key value of the accelerator
297 	 * accelMods = modifier combination of the accelerator
298 	 * Returns: an array of n_entries GtkAccelGroupEntry elements, or NULL. The array is owned by GTK+ and must not be freed. [allow-none]
299 	 */
300 	public GtkAccelGroupEntry[] query(uint accelKey, GdkModifierType accelMods)
301 	{
302 		// GtkAccelGroupEntry * gtk_accel_group_query (GtkAccelGroup *accel_group,  guint accel_key,  GdkModifierType accel_mods,  guint *n_entries);
303 		uint nEntries;
304 		auto p = gtk_accel_group_query(gtkAccelGroup, accelKey, accelMods, &nEntries);
305 		
306 		if(p is null)
307 		{
308 			return null;
309 		}
310 		
311 		return p[0 .. nEntries];
312 	}
313 	
314 	/**
315 	 * Finds the first accelerator in accel_group
316 	 * that matches accel_key and accel_mods, and
317 	 * activates it.
318 	 * Params:
319 	 * accelQuark = the quark for the accelerator name
320 	 * acceleratable = the GObject, usually a GtkWindow, on which
321 	 * to activate the accelerator.
322 	 * accelKey = accelerator keyval from a key event
323 	 * accelMods = keyboard state mask from a key event
324 	 * Returns: TRUE if an accelerator was activated and handled this keypress
325 	 */
326 	public int activate(GQuark accelQuark, ObjectG acceleratable, uint accelKey, GdkModifierType accelMods)
327 	{
328 		// gboolean gtk_accel_group_activate (GtkAccelGroup *accel_group,  GQuark accel_quark,  GObject *acceleratable,  guint accel_key,  GdkModifierType accel_mods);
329 		return gtk_accel_group_activate(gtkAccelGroup, accelQuark, (acceleratable is null) ? null : acceleratable.getObjectGStruct(), accelKey, accelMods);
330 	}
331 	
332 	/**
333 	 * Locks the given accelerator group.
334 	 * Locking an acelerator group prevents the accelerators contained
335 	 * within it to be changed during runtime. Refer to
336 	 * gtk_accel_map_change_entry() about runtime accelerator changes.
337 	 * If called more than once, accel_group remains locked until
338 	 * gtk_accel_group_unlock() has been called an equivalent number
339 	 * of times.
340 	 */
341 	public void lock()
342 	{
343 		// void gtk_accel_group_lock (GtkAccelGroup *accel_group);
344 		gtk_accel_group_lock(gtkAccelGroup);
345 	}
346 	
347 	/**
348 	 * Undoes the last call to gtk_accel_group_lock() on this accel_group.
349 	 */
350 	public void unlock()
351 	{
352 		// void gtk_accel_group_unlock (GtkAccelGroup *accel_group);
353 		gtk_accel_group_unlock(gtkAccelGroup);
354 	}
355 	
356 	/**
357 	 * Locks are added and removed using gtk_accel_group_lock() and
358 	 * gtk_accel_group_unlock().
359 	 * Since 2.14
360 	 * Returns: TRUE if there are 1 or more locks on the accel_group, FALSE otherwise.
361 	 */
362 	public int getIsLocked()
363 	{
364 		// gboolean gtk_accel_group_get_is_locked (GtkAccelGroup *accel_group);
365 		return gtk_accel_group_get_is_locked(gtkAccelGroup);
366 	}
367 	
368 	/**
369 	 * Finds the GtkAccelGroup to which closure is connected;
370 	 * see gtk_accel_group_connect().
371 	 * Params:
372 	 * closure = a GClosure
373 	 * Returns: the GtkAccelGroup to which closure is connected, or NULL. [transfer none]
374 	 */
375 	public static AccelGroup fromAccelClosure(Closure closure)
376 	{
377 		// GtkAccelGroup * gtk_accel_group_from_accel_closure (GClosure *closure);
378 		auto p = gtk_accel_group_from_accel_closure((closure is null) ? null : closure.getClosureStruct());
379 		
380 		if(p is null)
381 		{
382 			return null;
383 		}
384 		
385 		return ObjectG.getDObject!(AccelGroup)(cast(GtkAccelGroup*) p);
386 	}
387 	
388 	/**
389 	 * Gets a GdkModifierType representing the mask for this
390 	 * accel_group. For example, GDK_CONTROL_MASK, GDK_SHIFT_MASK, etc.
391 	 * Since 2.14
392 	 * Returns: the modifier mask for this accel group.
393 	 */
394 	public GdkModifierType getModifierMask()
395 	{
396 		// GdkModifierType gtk_accel_group_get_modifier_mask (GtkAccelGroup *accel_group);
397 		return gtk_accel_group_get_modifier_mask(gtkAccelGroup);
398 	}
399 	
400 	/**
401 	 * Finds the first accelerator in any GtkAccelGroup attached
402 	 * to object that matches accel_key and accel_mods, and
403 	 * activates that accelerator.
404 	 * Params:
405 	 * object = the GObject, usually a GtkWindow, on which
406 	 * to activate the accelerator.
407 	 * accelKey = accelerator keyval from a key event
408 	 * accelMods = keyboard state mask from a key event
409 	 * Returns: TRUE if an accelerator was activated and handled this keypress
410 	 */
411 	public static int accelGroupsActivate(ObjectG object, uint accelKey, GdkModifierType accelMods)
412 	{
413 		// gboolean gtk_accel_groups_activate (GObject *object,  guint accel_key,  GdkModifierType accel_mods);
414 		return gtk_accel_groups_activate((object is null) ? null : object.getObjectGStruct(), accelKey, accelMods);
415 	}
416 	
417 	/**
418 	 * Gets a list of all accel groups which are attached to object.
419 	 * Params:
420 	 * object = a GObject, usually a GtkWindow
421 	 * Returns: a list of all accel groups which are attached to object. [element-type GtkAccelGroup][transfer none]
422 	 */
423 	public static ListSG accelGroupsFromObject(ObjectG object)
424 	{
425 		// GSList * gtk_accel_groups_from_object (GObject *object);
426 		auto p = gtk_accel_groups_from_object((object is null) ? null : object.getObjectGStruct());
427 		
428 		if(p is null)
429 		{
430 			return null;
431 		}
432 		
433 		return ObjectG.getDObject!(ListSG)(cast(GSList*) p);
434 	}
435 	
436 	/**
437 	 * Finds the first entry in an accelerator group for which
438 	 * find_func returns TRUE and returns its GtkAccelKey.
439 	 * Params:
440 	 * findFunc = a function to filter the entries of accel_group with
441 	 * data = data to pass to find_func
442 	 * Returns: the key of the first entry passing find_func. The key is owned by GTK+ and must not be freed. [transfer none]
443 	 */
444 	public GtkAccelKey* find(GtkAccelGroupFindFunc findFunc, void* data)
445 	{
446 		// GtkAccelKey * gtk_accel_group_find (GtkAccelGroup *accel_group,  GtkAccelGroupFindFunc find_func,  gpointer data);
447 		return gtk_accel_group_find(gtkAccelGroup, findFunc, data);
448 	}
449 	
450 	/**
451 	 * Determines whether a given keyval and modifier mask constitute
452 	 * a valid keyboard accelerator. For example, the GDK_a keyval
453 	 * plus GDK_CONTROL_MASK is valid - this is a "Ctrl+a" accelerator.
454 	 * But, you can't, for instance, use the GDK_Control_L keyval
455 	 * as an accelerator.
456 	 * Params:
457 	 * keyval = a GDK keyval
458 	 * modifiers = modifier mask
459 	 * Returns: TRUE if the accelerator is valid
460 	 */
461 	public static int acceleratorValid(uint keyval, GdkModifierType modifiers)
462 	{
463 		// gboolean gtk_accelerator_valid (guint keyval,  GdkModifierType modifiers);
464 		return gtk_accelerator_valid(keyval, modifiers);
465 	}
466 	
467 	/**
468 	 * Parses a string representing an accelerator. The
469 	 * format looks like "<Control>a" or "<Shift><Alt>F1" or
470 	 * "<Release>z" (the last one is for key release).
471 	 * The parser is fairly liberal and allows lower or upper case,
472 	 * and also abbreviations such as "<Ctl>" and "<Ctrl>".
473 	 * Key names are parsed using gdk_keyval_from_name(). For character keys the
474 	 * name is not the symbol, but the lowercase name, e.g. one would use
475 	 * "<Ctrl>minus" instead of "<Ctrl>-".
476 	 * If the parse fails, accelerator_key and accelerator_mods will
477 	 * be set to 0 (zero).
478 	 * Params:
479 	 * accelerator = string representing an accelerator
480 	 * acceleratorKey = return location for accelerator keyval. [out][allow-none]
481 	 * acceleratorMods = return location for accelerator modifier mask. [out][allow-none]
482 	 */
483 	public static void acceleratorParse(string accelerator, out uint acceleratorKey, out GdkModifierType acceleratorMods)
484 	{
485 		// void gtk_accelerator_parse (const gchar *accelerator,  guint *accelerator_key,  GdkModifierType *accelerator_mods);
486 		gtk_accelerator_parse(Str.toStringz(accelerator), &acceleratorKey, &acceleratorMods);
487 	}
488 	
489 	/**
490 	 * Converts an accelerator keyval and modifier mask
491 	 * into a string parseable by gtk_accelerator_parse().
492 	 * For example, if you pass in GDK_q and GDK_CONTROL_MASK,
493 	 * this function returns "<Control>q".
494 	 * If you need to display accelerators in the user interface,
495 	 * see gtk_accelerator_get_label().
496 	 * Params:
497 	 * acceleratorKey = accelerator keyval
498 	 * acceleratorMods = accelerator modifier mask
499 	 * Returns: a newly-allocated accelerator name
500 	 */
501 	public static string acceleratorName(uint acceleratorKey, GdkModifierType acceleratorMods)
502 	{
503 		// gchar * gtk_accelerator_name (guint accelerator_key,  GdkModifierType accelerator_mods);
504 		return Str.toString(gtk_accelerator_name(acceleratorKey, acceleratorMods));
505 	}
506 	
507 	/**
508 	 * Converts an accelerator keyval and modifier mask into a string
509 	 * which can be used to represent the accelerator to the user.
510 	 * Since 2.6
511 	 * Params:
512 	 * acceleratorKey = accelerator keyval
513 	 * acceleratorMods = accelerator modifier mask
514 	 * Returns: a newly-allocated string representing the accelerator.
515 	 */
516 	public static string acceleratorGetLabel(uint acceleratorKey, GdkModifierType acceleratorMods)
517 	{
518 		// gchar * gtk_accelerator_get_label (guint accelerator_key,  GdkModifierType accelerator_mods);
519 		return Str.toString(gtk_accelerator_get_label(acceleratorKey, acceleratorMods));
520 	}
521 	
522 	/**
523 	 * Sets the modifiers that will be considered significant for keyboard
524 	 * accelerators. The default mod mask is GDK_CONTROL_MASK |
525 	 * GDK_SHIFT_MASK | GDK_MOD1_MASK | GDK_SUPER_MASK |
526 	 * GDK_HYPER_MASK | GDK_META_MASK, that is, Control, Shift, Alt,
527 	 * Super, Hyper and Meta. Other modifiers will by default be ignored
528 	 * by GtkAccelGroup.
529 	 * You must include at least the three modifiers Control, Shift
530 	 * and Alt in any value you pass to this function.
531 	 * The default mod mask should be changed on application startup,
532 	 * before using any accelerator groups.
533 	 * Params:
534 	 * defaultModMask = accelerator modifier mask
535 	 */
536 	public static void acceleratorSetDefaultModMask(GdkModifierType defaultModMask)
537 	{
538 		// void gtk_accelerator_set_default_mod_mask  (GdkModifierType default_mod_mask);
539 		gtk_accelerator_set_default_mod_mask(defaultModMask);
540 	}
541 	
542 	/**
543 	 * Gets the value set by gtk_accelerator_set_default_mod_mask().
544 	 * Returns: the default accelerator modifier mask
545 	 */
546 	public static uint acceleratorGetDefaultModMask()
547 	{
548 		// guint gtk_accelerator_get_default_mod_mask  (void);
549 		return gtk_accelerator_get_default_mod_mask();
550 	}
551 }