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
27 * outFile = AccelGroup
28 * strct = GtkAccelGroup
51 * - GClosure* -> Closure
52 * - GObject* -> ObjectG
54 * - GtkAccelGroup* -> AccelGroup
59 module gtk
.AccelGroup
;
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
;
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
)
127 if ( gtkAccelGroup
is null )
132 Stdout("struct gtkAccelGroup is null on constructor").newline
;
136 printf("struct gtkAccelGroup is null on constructor");
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
) )
165 cast(GCallback
)&callBackAccelActivate
,
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
);
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
) )
193 cast(GCallback
)&callBackAccelChanged
,
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
);
216 * Creates a new GtkAccelGroup.
218 * a new GtkAccelGroup object
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.
237 * the accelerator group to install an accelerator in
239 * key value of the accelerator
241 * modifier combination of the accelerator
243 * a flag mask to configure this accelerator
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
260 * The signature used for the closure is that of GtkAccelGroupActivate.
262 * the accelerator group to install an accelerator in
264 * path used for determining key and modifiers.
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().
280 * the accelerator group to remove an accelerator from
282 * the closure to remove from this accelerator group
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().
296 * the accelerator group to install an accelerator in
298 * key value of the accelerator
300 * modifier combination of the accelerator
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
315 * the accelerator group to query
317 * key value of the accelerator
319 * modifier combination of the accelerator
321 * location to return the number of entries found, or NULL
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
);
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
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.
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().
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
394 * the GObject, usually a GtkWindow, on which
395 * to activate the accelerator.
397 * accelerator keyval from a key event
399 * keyboard state mask from a key event
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.
412 * a GObject, usually a GtkWindow
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.
428 * a function to filter the entries of accel_group with
430 * data to pass to find_func
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
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).
470 * string representing an accelerator
472 * return location for accelerator keyval
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().
492 * accelerator modifier mask
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.
508 * accelerator modifier mask
510 * a newly-allocated string representing the accelerator.
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
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.
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().
542 * the default accelerator modifier mask
544 * The "accel-activate" signal
545 * gboolean user_function (GtkAccelGroup *accel_group,
546 * GObject *acceleratable,
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.
553 * the GtkAccelGroup which received the signal
555 * the object on which the accelerator was activated
557 * the accelerator keyval
559 * the modifier combination of the accelerator
561 * user data set when the signal handler was connected.
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();