alternative to assert
[gtkD.git] / gtkD / src / gtk / AccelGroup.d
blob3d71f735b931b7399f9e6e42c01a988b1c0bc18e
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = gtk-Keyboard-Accelerators.html
26 * outPack = gtk
27 * outFile = AccelGroup
28 * strct = GtkAccelGroup
29 * realStrct=
30 * ctorStrct=
31 * clss = AccelGroup
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gtk_accel_group_
40 * - gtk_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * imports:
45 * - glib.Str
46 * - gobject.Closure
47 * - gobject.ObjectG
48 * - gtk.AccelGroup
49 * - glib.ListSG
50 * structWrap:
51 * - GClosure* -> Closure
52 * - GObject* -> ObjectG
53 * - GSList* -> ListSG
54 * - GtkAccelGroup* -> AccelGroup
55 * module aliases:
56 * local aliases:
59 module gtk.AccelGroup;
61 version(noAssert)
63 version(Tango)
65 import tango.io.Stdout; // use the tango loging?
69 private import gtkc.gtktypes;
71 private import gtkc.gtk;
74 private import glib.Str;
75 private import gobject.Closure;
76 private import gobject.ObjectG;
77 private import gtk.AccelGroup;
78 private import glib.ListSG;
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.
100 private import gobject.ObjectG;
101 public class AccelGroup : ObjectG
104 /** the main Gtk struct */
105 protected GtkAccelGroup* gtkAccelGroup;
108 public GtkAccelGroup* getAccelGroupStruct()
110 return gtkAccelGroup;
114 /** the main Gtk struct as a void* */
115 protected void* getStruct()
117 return cast(void*)gtkAccelGroup;
121 * Sets our main struct and passes it to the parent class
123 public this (GtkAccelGroup* gtkAccelGroup)
125 version(noAssert)
127 if ( gtkAccelGroup is null )
129 int zero = 0;
130 version(Tango)
132 Stdout("struct gtkAccelGroup is null on constructor").newline;
134 else
136 printf("struct gtkAccelGroup is null on constructor");
138 zero = zero / zero;
141 else
143 assert(gtkAccelGroup !is null, "struct gtkAccelGroup is null on constructor");
145 super(cast(GObject*)gtkAccelGroup);
146 this.gtkAccelGroup = gtkAccelGroup;
152 // imports for the signal processing
153 private import gobject.Signals;
154 private import gtkc.gdktypes;
155 int[char[]] connectedSignals;
157 gboolean delegate(ObjectG, guint, GdkModifierType, AccelGroup)[] onAccelActivateListeners;
158 void addOnAccelActivate(gboolean delegate(ObjectG, guint, GdkModifierType, AccelGroup) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
160 if ( !("accel-activate" in connectedSignals) )
162 Signals.connectData(
163 getStruct(),
164 "accel-activate",
165 cast(GCallback)&callBackAccelActivate,
166 cast(void*)this,
167 null,
168 connectFlags);
169 connectedSignals["accel-activate"] = 1;
171 onAccelActivateListeners ~= dlg;
173 extern(C) static void callBackAccelActivate(GtkAccelGroup* accelGroupStruct, GObject* acceleratable, guint keyval, GdkModifierType modifier, AccelGroup accelGroup)
175 bool consumed = false;
177 foreach ( gboolean delegate(ObjectG, guint, GdkModifierType, AccelGroup) dlg ; accelGroup.onAccelActivateListeners )
179 dlg(new ObjectG(acceleratable), keyval, modifier, accelGroup);
182 return consumed;
185 void delegate(guint, GdkModifierType, Closure, AccelGroup)[] onAccelChangedListeners;
186 void addOnAccelChanged(void delegate(guint, GdkModifierType, Closure, AccelGroup) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
188 if ( !("accel-changed" in connectedSignals) )
190 Signals.connectData(
191 getStruct(),
192 "accel-changed",
193 cast(GCallback)&callBackAccelChanged,
194 cast(void*)this,
195 null,
196 connectFlags);
197 connectedSignals["accel-changed"] = 1;
199 onAccelChangedListeners ~= dlg;
201 extern(C) static void callBackAccelChanged(GtkAccelGroup* accelGroupStruct, guint keyval, GdkModifierType modifier, GClosure* accelClosure, AccelGroup accelGroup)
203 bool consumed = false;
205 foreach ( void delegate(guint, GdkModifierType, Closure, AccelGroup) dlg ; accelGroup.onAccelChangedListeners )
207 dlg(keyval, modifier, new Closure(accelClosure), accelGroup);
210 return consumed;
216 * Creates a new GtkAccelGroup.
217 * Returns:
218 * a new GtkAccelGroup object
220 public this ()
222 // GtkAccelGroup* gtk_accel_group_new (void);
223 this(cast(GtkAccelGroup*)gtk_accel_group_new() );
229 * Installs an accelerator in this group. When accel_group is being activated
230 * in response to a call to gtk_accel_groups_activate(), closure will be
231 * invoked if the accel_key and accel_mods from gtk_accel_groups_activate()
232 * match those of this connection.
233 * The signature used for the closure is that of GtkAccelGroupActivate.
234 * Note that, due to implementation details, a single closure can only be
235 * connected to one accelerator group.
236 * accel_group:
237 * the accelerator group to install an accelerator in
238 * accel_key:
239 * key value of the accelerator
240 * accel_mods:
241 * modifier combination of the accelerator
242 * accel_flags:
243 * a flag mask to configure this accelerator
244 * closure:
245 * closure to be executed upon accelerator activation
247 public void connect(uint accelKey, GdkModifierType accelMods, GtkAccelFlags accelFlags, Closure closure)
249 // void gtk_accel_group_connect (GtkAccelGroup *accel_group, guint accel_key, GdkModifierType accel_mods, GtkAccelFlags accel_flags, GClosure *closure);
250 gtk_accel_group_connect(gtkAccelGroup, accelKey, accelMods, accelFlags, (closure is null) ? null : closure.getClosureStruct());
254 * Installs an accelerator in this group, using an accelerator path to look
255 * up the appropriate key and modifiers (see gtk_accel_map_add_entry()).
256 * When accel_group is being activated in response to a call to
257 * gtk_accel_groups_activate(), closure will be invoked if the accel_key and
258 * accel_mods from gtk_accel_groups_activate() match the key and modifiers
259 * for the path.
260 * The signature used for the closure is that of GtkAccelGroupActivate.
261 * accel_group:
262 * the accelerator group to install an accelerator in
263 * accel_path:
264 * path used for determining key and modifiers.
265 * closure:
266 * closure to be executed upon accelerator activation
268 public void connectByPath(char[] accelPath, Closure closure)
270 // void gtk_accel_group_connect_by_path (GtkAccelGroup *accel_group, const gchar *accel_path, GClosure *closure);
271 gtk_accel_group_connect_by_path(gtkAccelGroup, Str.toStringz(accelPath), (closure is null) ? null : closure.getClosureStruct());
277 * Removes an accelerator previously installed through
278 * gtk_accel_group_connect().
279 * accel_group:
280 * the accelerator group to remove an accelerator from
281 * closure:
282 * the closure to remove from this accelerator group
283 * Returns:
284 * TRUE if the closure was found and got disconnected
286 public int disconnect(Closure closure)
288 // gboolean gtk_accel_group_disconnect (GtkAccelGroup *accel_group, GClosure *closure);
289 return gtk_accel_group_disconnect(gtkAccelGroup, (closure is null) ? null : closure.getClosureStruct());
293 * Removes an accelerator previously installed through
294 * gtk_accel_group_connect().
295 * accel_group:
296 * the accelerator group to install an accelerator in
297 * accel_key:
298 * key value of the accelerator
299 * accel_mods:
300 * modifier combination of the accelerator
301 * Returns:
302 * TRUE if there was an accelerator which could be
303 * removed, FALSE otherwise
305 public int disconnectKey(uint accelKey, GdkModifierType accelMods)
307 // gboolean gtk_accel_group_disconnect_key (GtkAccelGroup *accel_group, guint accel_key, GdkModifierType accel_mods);
308 return gtk_accel_group_disconnect_key(gtkAccelGroup, accelKey, accelMods);
312 * Queries an accelerator group for all entries matching accel_key and
313 * accel_mods.
314 * accel_group:
315 * the accelerator group to query
316 * accel_key:
317 * key value of the accelerator
318 * accel_mods:
319 * modifier combination of the accelerator
320 * n_entries:
321 * location to return the number of entries found, or NULL
322 * Returns:
323 * an array of n_entries GtkAccelGroupEntry elements, or NULL. The array is owned by GTK+ and must not be freed.
325 public GtkAccelGroupEntry* query(uint accelKey, GdkModifierType accelMods, uint* nEntries)
327 // GtkAccelGroupEntry* gtk_accel_group_query (GtkAccelGroup *accel_group, guint accel_key, GdkModifierType accel_mods, guint *n_entries);
328 return gtk_accel_group_query(gtkAccelGroup, accelKey, accelMods, nEntries);
332 * accel_group:
333 * accel_quark:
334 * acceleratable:
335 * accel_key:
336 * accel_mods:
337 * Returns:
339 public int activate(GQuark accelQuark, ObjectG acceleratable, uint accelKey, GdkModifierType accelMods)
341 // gboolean gtk_accel_group_activate (GtkAccelGroup *accel_group, GQuark accel_quark, GObject *acceleratable, guint accel_key, GdkModifierType accel_mods);
342 return gtk_accel_group_activate(gtkAccelGroup, accelQuark, (acceleratable is null) ? null : acceleratable.getObjectGStruct(), accelKey, accelMods);
346 * Locks the given accelerator group.
347 * Locking an acelerator group prevents the accelerators contained
348 * within it to be changed during runtime. Refer to
349 * gtk_accel_map_change_entry() about runtime accelerator changes.
350 * If called more than once, accel_group remains locked until
351 * gtk_accel_group_unlock() has been called an equivalent number
352 * of times.
353 * accel_group:
354 * a GtkAccelGroup
356 public void lock()
358 // void gtk_accel_group_lock (GtkAccelGroup *accel_group);
359 gtk_accel_group_lock(gtkAccelGroup);
363 * Undoes the last call to gtk_accel_group_lock() on this accel_group.
364 * accel_group:
365 * a GtkAccelGroup
367 public void unlock()
369 // void gtk_accel_group_unlock (GtkAccelGroup *accel_group);
370 gtk_accel_group_unlock(gtkAccelGroup);
374 * Finds the GtkAccelGroup to which closure is connected;
375 * see gtk_accel_group_connect().
376 * closure:
377 * a GClosure
378 * Returns:
379 * the GtkAccelGroup to which closure is connected, or NULL.
381 public static AccelGroup fromAccelClosure(Closure closure)
383 // GtkAccelGroup* gtk_accel_group_from_accel_closure (GClosure *closure);
384 return new AccelGroup( gtk_accel_group_from_accel_closure((closure is null) ? null : closure.getClosureStruct()) );
388 * Finds the first accelerator in any GtkAccelGroup attached
389 * to object that matches accel_key and accel_mods, and
390 * activates that accelerator.
391 * If an accelerator was activated and handled this keypress, TRUE
392 * is returned.
393 * object:
394 * the GObject, usually a GtkWindow, on which
395 * to activate the accelerator.
396 * accel_key:
397 * accelerator keyval from a key event
398 * accel_mods:
399 * keyboard state mask from a key event
400 * Returns:
401 * TRUE if the accelerator was handled, FALSE otherwise
403 public static int accelGroupsActivate(ObjectG object, uint accelKey, GdkModifierType accelMods)
405 // gboolean gtk_accel_groups_activate (GObject *object, guint accel_key, GdkModifierType accel_mods);
406 return gtk_accel_groups_activate((object is null) ? null : object.getObjectGStruct(), accelKey, accelMods);
410 * Gets a list of all accel groups which are attached to object.
411 * object:
412 * a GObject, usually a GtkWindow
413 * Returns:
414 * a list of all accel groups which are attached to object
416 public static ListSG accelGroupsFromObject(ObjectG object)
418 // GSList* gtk_accel_groups_from_object (GObject *object);
419 return new ListSG( gtk_accel_groups_from_object((object is null) ? null : object.getObjectGStruct()) );
423 * Finds the first entry in an accelerator group for which
424 * find_func returns TRUE and returns its GtkAccelKey.
425 * accel_group:
426 * a GtkAccelGroup
427 * find_func:
428 * a function to filter the entries of accel_group with
429 * data:
430 * data to pass to find_func
431 * Returns:
432 * the key of the first entry passing find_func. The key is
433 * owned by GTK+ and must not be freed.
435 public GtkAccelKey* find(GtkAccelGroupFindFunc findFunc, void* data)
437 // GtkAccelKey* gtk_accel_group_find (GtkAccelGroup *accel_group, GtkAccelGroupFindFunc find_func, gpointer data);
438 return gtk_accel_group_find(gtkAccelGroup, findFunc, data);
443 * Determines whether a given keyval and modifier mask constitute
444 * a valid keyboard accelerator. For example, the GDK_a keyval
445 * plus GDK_CONTROL_MASK is valid - this is a "Ctrl+a" accelerator.
446 * But, you can't, for instance, use the GDK_Control_L keyval
447 * as an accelerator.
448 * keyval:
449 * a GDK keyval
450 * modifiers:
451 * modifier mask
452 * Returns:
453 * TRUE if the accelerator is valid
455 public static int acceleratorValid(uint keyval, GdkModifierType modifiers)
457 // gboolean gtk_accelerator_valid (guint keyval, GdkModifierType modifiers);
458 return gtk_accelerator_valid(keyval, modifiers);
462 * Parses a string representing an accelerator. The
463 * format looks like "<Control>a" or "<Shift><Alt>F1" or
464 * "<Release>z" (the last one is for key release).
465 * The parser is fairly liberal and allows lower or upper case,
466 * and also abbreviations such as "<Ctl>" and "<Ctrl>".
467 * If the parse fails, accelerator_key and accelerator_mods will
468 * be set to 0 (zero).
469 * accelerator:
470 * string representing an accelerator
471 * accelerator_key:
472 * return location for accelerator keyval
473 * accelerator_mods:
474 * return location for accelerator modifier mask
476 public static void acceleratorParse(char[] accelerator, uint* acceleratorKey, GdkModifierType* acceleratorMods)
478 // void gtk_accelerator_parse (const gchar *accelerator, guint *accelerator_key, GdkModifierType *accelerator_mods);
479 gtk_accelerator_parse(Str.toStringz(accelerator), acceleratorKey, acceleratorMods);
483 * Converts an accelerator keyval and modifier mask
484 * into a string parseable by gtk_accelerator_parse().
485 * For example, if you pass in GDK_q and GDK_CONTROL_MASK,
486 * this function returns "<Control>q".
487 * If you need to display accelerators in the user interface,
488 * see gtk_accelerator_get_label().
489 * accelerator_key:
490 * accelerator keyval
491 * accelerator_mods:
492 * accelerator modifier mask
493 * Returns:
494 * a newly-allocated accelerator name
496 public static char[] acceleratorName(uint acceleratorKey, GdkModifierType acceleratorMods)
498 // gchar* gtk_accelerator_name (guint accelerator_key, GdkModifierType accelerator_mods);
499 return Str.toString(gtk_accelerator_name(acceleratorKey, acceleratorMods) );
503 * Converts an accelerator keyval and modifier mask into a string
504 * which can be used to represent the accelerator to the user.
505 * accelerator_key:
506 * accelerator keyval
507 * accelerator_mods:
508 * accelerator modifier mask
509 * Returns:
510 * a newly-allocated string representing the accelerator.
511 * Since 2.6
513 public static char[] acceleratorGetLabel(uint acceleratorKey, GdkModifierType acceleratorMods)
515 // gchar* gtk_accelerator_get_label (guint accelerator_key, GdkModifierType accelerator_mods);
516 return Str.toString(gtk_accelerator_get_label(acceleratorKey, acceleratorMods) );
520 * Sets the modifiers that will be considered significant for keyboard
521 * accelerators. The default mod mask is GDK_CONTROL_MASK |
522 * GDK_SHIFT_MASK | GDK_MOD1_MASK | GDK_SUPER_MASK |
523 * GDK_HYPER_MASK | GDK_META_MASK, that is, Control, Shift, Alt,
524 * Super, Hyper and Meta. Other modifiers will by default be ignored
525 * by GtkAccelGroup.
526 * You must include at least the three modifiers Control, Shift
527 * and Alt in any value you pass to this function.
528 * The default mod mask should be changed on application startup,
529 * before using any accelerator groups.
530 * default_mod_mask:
531 * accelerator modifier mask
533 public static void acceleratorSetDefaultModMask(GdkModifierType defaultModMask)
535 // void gtk_accelerator_set_default_mod_mask (GdkModifierType default_mod_mask);
536 gtk_accelerator_set_default_mod_mask(defaultModMask);
540 * Gets the value set by gtk_accelerator_set_default_mod_mask().
541 * Returns:
542 * the default accelerator modifier mask
543 * Signal Details
544 * The "accel-activate" signal
545 * gboolean user_function (GtkAccelGroup *accel_group,
546 * GObject *acceleratable,
547 * guint keyval,
548 * GdkModifierType modifier,
549 * gpointer user_data) : Has Details
550 * The accel-activate signal is an implementation detail of
551 * GtkAccelGroup and not meant to be used by applications.
552 * accel_group:
553 * the GtkAccelGroup which received the signal
554 * acceleratable:
555 * the object on which the accelerator was activated
556 * keyval:
557 * the accelerator keyval
558 * modifier:
559 * the modifier combination of the accelerator
560 * user_data:
561 * user data set when the signal handler was connected.
562 * Returns:
563 * TRUE if the accelerator was activated
565 public static uint acceleratorGetDefaultModMask()
567 // guint gtk_accelerator_get_default_mod_mask (void);
568 return gtk_accelerator_get_default_mod_mask();