1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #define GTK_MENU_INTERNALS
30 #include "gdk/gdkkeysyms.h"
31 #include "gtkbindings.h"
32 #include "gtkkeyhash.h"
34 #include "gtkmarshalers.h"
36 #include "gtkmenubar.h"
37 #include "gtkmenuitem.h"
38 #include "gtkmenushell.h"
39 #include "gtkmnemonichash.h"
40 #include "gtktearoffmenuitem.h"
41 #include "gtkwindow.h"
42 #include "gtkprivate.h"
46 #define MENU_SHELL_TIMEOUT 500
48 #define PACK_DIRECTION(m) \
49 (GTK_IS_MENU_BAR (m) \
50 ? gtk_menu_bar_get_pack_direction (GTK_MENU_BAR (m)) \
51 : GTK_PACK_DIRECTION_LTR)
71 * A menu item can be "selected", this means that it is displayed
72 * in the prelight state, and if it has a submenu, that submenu
75 * A menu is "active" when it is visible onscreen and the user
76 * is selecting from it. A menubar is not active until the user
77 * clicks on one of its menuitems. When a menu is active,
78 * passing the mouse over a submenu will pop it up.
80 * menu_shell->active_menu_item, is however, not an "active"
81 * menu item (there is no such thing) but rather, the selected
82 * menu item in that MenuShell, if there is one.
84 * There is also is a concept of the current menu and a current
85 * menu item. The current menu item is the selected menu item
86 * that is furthest down in the heirarchy. (Every active menu_shell
87 * does not necessarily contain a selected menu item, but if
88 * it does, then menu_shell->parent_menu_shell must also contain
89 * a selected menu item. The current menu is the menu that
90 * contains the current menu_item. It will always have a GTK
91 * grab and receive all key presses.
96 * ::move_current (GtkMenuDirection *dir)
97 * Moves the current menu item in direction 'dir':
99 * GTK_MENU_DIR_PARENT: To the parent menu shell
100 * GTK_MENU_DIR_CHILD: To the child menu shell (if this item has
102 * GTK_MENU_DIR_NEXT/PREV: To the next or previous item
105 * As a a bit of a hack to get movement between menus and
106 * menubars working, if submenu_placement is different for
107 * the menu and its MenuShell then the following apply:
109 * - For 'parent' the current menu is not just moved to
110 * the parent, but moved to the previous entry in the parent
111 * - For 'child', if there is no child, then current is
112 * moved to the next item in the parent.
114 * Note that the above explanation of ::move_current was written
115 * before menus and menubars had support for RTL flipping and
116 * different packing directions, and therefore only applies for
117 * when text direction and packing direction are both left-to-right.
119 * ::activate_current (GBoolean *force_hide)
120 * Activate the current item. If 'force_hide' is true, hide
121 * the current menu item always. Otherwise, only hide
122 * it if menu_item->klass->hide_on_activate is true.
125 * Cancels the current selection
128 #define GTK_MENU_SHELL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_MENU_SHELL, GtkMenuShellPrivate))
130 typedef struct _GtkMenuShellPrivate GtkMenuShellPrivate;
132 struct _GtkMenuShellPrivate
134 GtkMnemonicHash *mnemonic_hash;
135 GtkKeyHash *key_hash;
137 guint take_focus : 1;
138 guint activated_submenu : 1;
141 static void gtk_menu_shell_set_property (GObject *object,
145 static void gtk_menu_shell_get_property (GObject *object,
149 static void gtk_menu_shell_realize (GtkWidget *widget);
150 static void gtk_menu_shell_finalize (GObject *object);
151 static gint gtk_menu_shell_button_press (GtkWidget *widget,
152 GdkEventButton *event);
153 static gint gtk_menu_shell_button_release (GtkWidget *widget,
154 GdkEventButton *event);
155 static gint gtk_menu_shell_key_press (GtkWidget *widget,
157 static gint gtk_menu_shell_enter_notify (GtkWidget *widget,
158 GdkEventCrossing *event);
159 static gint gtk_menu_shell_leave_notify (GtkWidget *widget,
160 GdkEventCrossing *event);
161 static void gtk_menu_shell_screen_changed (GtkWidget *widget,
162 GdkScreen *previous_screen);
163 static gboolean gtk_menu_shell_grab_broken (GtkWidget *widget,
164 GdkEventGrabBroken *event);
165 static void gtk_menu_shell_add (GtkContainer *container,
167 static void gtk_menu_shell_remove (GtkContainer *container,
169 static void gtk_menu_shell_forall (GtkContainer *container,
170 gboolean include_internals,
171 GtkCallback callback,
172 gpointer callback_data);
173 static void gtk_menu_shell_real_insert (GtkMenuShell *menu_shell,
176 static void gtk_real_menu_shell_deactivate (GtkMenuShell *menu_shell);
177 static gint gtk_menu_shell_is_item (GtkMenuShell *menu_shell,
179 static GtkWidget *gtk_menu_shell_get_item (GtkMenuShell *menu_shell,
181 static GType gtk_menu_shell_child_type (GtkContainer *container);
182 static void gtk_menu_shell_real_select_item (GtkMenuShell *menu_shell,
183 GtkWidget *menu_item);
184 static gboolean gtk_menu_shell_select_submenu_first (GtkMenuShell *menu_shell);
186 static void gtk_real_menu_shell_move_current (GtkMenuShell *menu_shell,
187 GtkMenuDirectionType direction);
188 static void gtk_real_menu_shell_activate_current (GtkMenuShell *menu_shell,
189 gboolean force_hide);
190 static void gtk_real_menu_shell_cancel (GtkMenuShell *menu_shell);
191 static void gtk_real_menu_shell_cycle_focus (GtkMenuShell *menu_shell,
192 GtkDirectionType dir);
194 static void gtk_menu_shell_reset_key_hash (GtkMenuShell *menu_shell);
195 static gboolean gtk_menu_shell_activate_mnemonic (GtkMenuShell *menu_shell,
197 static gboolean gtk_menu_shell_real_move_selected (GtkMenuShell *menu_shell,
200 static guint menu_shell_signals[LAST_SIGNAL] = { 0 };
202 G_DEFINE_ABSTRACT_TYPE (GtkMenuShell, gtk_menu_shell, GTK_TYPE_CONTAINER)
205 gtk_menu_shell_class_init (GtkMenuShellClass *klass)
207 GObjectClass *object_class;
208 GtkWidgetClass *widget_class;
209 GtkContainerClass *container_class;
211 GtkBindingSet *binding_set;
213 object_class = (GObjectClass*) klass;
214 widget_class = (GtkWidgetClass*) klass;
215 container_class = (GtkContainerClass*) klass;
217 object_class->set_property = gtk_menu_shell_set_property;
218 object_class->get_property = gtk_menu_shell_get_property;
219 object_class->finalize = gtk_menu_shell_finalize;
221 widget_class->realize = gtk_menu_shell_realize;
222 widget_class->button_press_event = gtk_menu_shell_button_press;
223 widget_class->button_release_event = gtk_menu_shell_button_release;
224 widget_class->grab_broken_event = gtk_menu_shell_grab_broken;
225 widget_class->key_press_event = gtk_menu_shell_key_press;
226 widget_class->enter_notify_event = gtk_menu_shell_enter_notify;
227 widget_class->leave_notify_event = gtk_menu_shell_leave_notify;
228 widget_class->screen_changed = gtk_menu_shell_screen_changed;
230 container_class->add = gtk_menu_shell_add;
231 container_class->remove = gtk_menu_shell_remove;
232 container_class->forall = gtk_menu_shell_forall;
233 container_class->child_type = gtk_menu_shell_child_type;
235 klass->submenu_placement = GTK_TOP_BOTTOM;
236 klass->deactivate = gtk_real_menu_shell_deactivate;
237 klass->selection_done = NULL;
238 klass->move_current = gtk_real_menu_shell_move_current;
239 klass->activate_current = gtk_real_menu_shell_activate_current;
240 klass->cancel = gtk_real_menu_shell_cancel;
241 klass->select_item = gtk_menu_shell_real_select_item;
242 klass->insert = gtk_menu_shell_real_insert;
243 klass->move_selected = gtk_menu_shell_real_move_selected;
245 menu_shell_signals[DEACTIVATE] =
246 g_signal_new (I_("deactivate"),
247 G_OBJECT_CLASS_TYPE (object_class),
249 G_STRUCT_OFFSET (GtkMenuShellClass, deactivate),
251 _gtk_marshal_VOID__VOID,
254 menu_shell_signals[SELECTION_DONE] =
255 g_signal_new (I_("selection-done"),
256 G_OBJECT_CLASS_TYPE (object_class),
258 G_STRUCT_OFFSET (GtkMenuShellClass, selection_done),
260 _gtk_marshal_VOID__VOID,
263 menu_shell_signals[MOVE_CURRENT] =
264 g_signal_new (I_("move-current"),
265 G_OBJECT_CLASS_TYPE (object_class),
266 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
267 G_STRUCT_OFFSET (GtkMenuShellClass, move_current),
269 _gtk_marshal_VOID__ENUM,
271 GTK_TYPE_MENU_DIRECTION_TYPE);
273 menu_shell_signals[ACTIVATE_CURRENT] =
274 g_signal_new (I_("activate-current"),
275 G_OBJECT_CLASS_TYPE (object_class),
276 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
277 G_STRUCT_OFFSET (GtkMenuShellClass, activate_current),
279 _gtk_marshal_VOID__BOOLEAN,
283 menu_shell_signals[CANCEL] =
284 g_signal_new (I_("cancel"),
285 G_OBJECT_CLASS_TYPE (object_class),
286 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
287 G_STRUCT_OFFSET (GtkMenuShellClass, cancel),
289 _gtk_marshal_VOID__VOID,
292 menu_shell_signals[CYCLE_FOCUS] =
293 g_signal_new_class_handler (I_("cycle-focus"),
294 G_OBJECT_CLASS_TYPE (object_class),
295 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
296 G_CALLBACK (gtk_real_menu_shell_cycle_focus),
298 _gtk_marshal_VOID__ENUM,
300 GTK_TYPE_DIRECTION_TYPE);
303 * GtkMenuShell::move-selected:
304 * @menu_shell: the object on which the signal is emitted
305 * @distance: +1 to move to the next item, -1 to move to the previous
307 * The ::move-selected signal is emitted to move the selection to
310 * Returns: %TRUE to stop the signal emission, %FALSE to continue
314 menu_shell_signals[MOVE_SELECTED] =
315 g_signal_new (I_("move-selected"),
316 G_OBJECT_CLASS_TYPE (object_class),
318 G_STRUCT_OFFSET (GtkMenuShellClass, move_selected),
319 _gtk_boolean_handled_accumulator, NULL,
320 _gtk_marshal_BOOLEAN__INT,
324 binding_set = gtk_binding_set_by_class (klass);
325 gtk_binding_entry_add_signal (binding_set,
328 gtk_binding_entry_add_signal (binding_set,
330 "activate-current", 1,
333 gtk_binding_entry_add_signal (binding_set,
335 "activate-current", 1,
338 gtk_binding_entry_add_signal (binding_set,
340 "activate-current", 1,
343 gtk_binding_entry_add_signal (binding_set,
345 "activate-current", 1,
348 gtk_binding_entry_add_signal (binding_set,
350 "activate-current", 1,
353 gtk_binding_entry_add_signal (binding_set,
356 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_FORWARD);
357 gtk_binding_entry_add_signal (binding_set,
358 GDK_F10, GDK_SHIFT_MASK,
360 GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
363 * GtkMenuShell:take-focus:
365 * A boolean that determines whether the menu and its submenus grab the
366 * keyboard focus. See gtk_menu_shell_set_take_focus() and
367 * gtk_menu_shell_get_take_focus().
371 g_object_class_install_property (object_class,
373 g_param_spec_boolean ("take-focus",
375 P_("A boolean that determines whether the menu grabs the keyboard focus"),
377 GTK_PARAM_READWRITE));
379 g_type_class_add_private (object_class, sizeof (GtkMenuShellPrivate));
383 gtk_menu_shell_child_type (GtkContainer *container)
385 return GTK_TYPE_MENU_ITEM;
389 gtk_menu_shell_init (GtkMenuShell *menu_shell)
391 GtkMenuShellPrivate *priv = GTK_MENU_SHELL_GET_PRIVATE (menu_shell);
393 menu_shell->children = NULL;
394 menu_shell->active_menu_item = NULL;
395 menu_shell->parent_menu_shell = NULL;
396 menu_shell->active = FALSE;
397 menu_shell->have_grab = FALSE;
398 menu_shell->have_xgrab = FALSE;
399 menu_shell->button = 0;
400 menu_shell->activate_time = 0;
402 priv->mnemonic_hash = NULL;
403 priv->key_hash = NULL;
404 priv->take_focus = TRUE;
405 priv->activated_submenu = FALSE;
409 gtk_menu_shell_set_property (GObject *object,
414 GtkMenuShell *menu_shell = GTK_MENU_SHELL (object);
418 case PROP_TAKE_FOCUS:
419 gtk_menu_shell_set_take_focus (menu_shell, g_value_get_boolean (value));
422 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
428 gtk_menu_shell_get_property (GObject *object,
433 GtkMenuShell *menu_shell = GTK_MENU_SHELL (object);
437 case PROP_TAKE_FOCUS:
438 g_value_set_boolean (value, gtk_menu_shell_get_take_focus (menu_shell));
441 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
447 gtk_menu_shell_finalize (GObject *object)
449 GtkMenuShell *menu_shell = GTK_MENU_SHELL (object);
450 GtkMenuShellPrivate *priv = GTK_MENU_SHELL_GET_PRIVATE (menu_shell);
452 if (priv->mnemonic_hash)
453 _gtk_mnemonic_hash_free (priv->mnemonic_hash);
455 _gtk_key_hash_free (priv->key_hash);
457 G_OBJECT_CLASS (gtk_menu_shell_parent_class)->finalize (object);
462 gtk_menu_shell_append (GtkMenuShell *menu_shell,
465 gtk_menu_shell_insert (menu_shell, child, -1);
469 gtk_menu_shell_prepend (GtkMenuShell *menu_shell,
472 gtk_menu_shell_insert (menu_shell, child, 0);
476 gtk_menu_shell_insert (GtkMenuShell *menu_shell,
480 GtkMenuShellClass *class;
482 g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
483 g_return_if_fail (GTK_IS_MENU_ITEM (child));
485 class = GTK_MENU_SHELL_GET_CLASS (menu_shell);
488 class->insert (menu_shell, child, position);
492 gtk_menu_shell_real_insert (GtkMenuShell *menu_shell,
496 menu_shell->children = g_list_insert (menu_shell->children, child, position);
498 gtk_widget_set_parent (child, GTK_WIDGET (menu_shell));
502 gtk_menu_shell_deactivate (GtkMenuShell *menu_shell)
504 g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
506 g_signal_emit (menu_shell, menu_shell_signals[DEACTIVATE], 0);
510 gtk_menu_shell_realize (GtkWidget *widget)
512 GdkWindowAttr attributes;
513 gint attributes_mask;
515 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
517 attributes.x = widget->allocation.x;
518 attributes.y = widget->allocation.y;
519 attributes.width = widget->allocation.width;
520 attributes.height = widget->allocation.height;
521 attributes.window_type = GDK_WINDOW_CHILD;
522 attributes.wclass = GDK_INPUT_OUTPUT;
523 attributes.visual = gtk_widget_get_visual (widget);
524 attributes.colormap = gtk_widget_get_colormap (widget);
525 attributes.event_mask = gtk_widget_get_events (widget);
526 attributes.event_mask |= (GDK_EXPOSURE_MASK |
527 GDK_BUTTON_PRESS_MASK |
528 GDK_BUTTON_RELEASE_MASK |
530 GDK_ENTER_NOTIFY_MASK |
531 GDK_LEAVE_NOTIFY_MASK);
533 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
534 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
535 gdk_window_set_user_data (widget->window, widget);
537 widget->style = gtk_style_attach (widget->style, widget->window);
538 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
542 _gtk_menu_shell_activate (GtkMenuShell *menu_shell)
544 if (!menu_shell->active)
546 gtk_grab_add (GTK_WIDGET (menu_shell));
547 menu_shell->have_grab = TRUE;
548 menu_shell->active = TRUE;
553 gtk_menu_shell_button_press (GtkWidget *widget,
554 GdkEventButton *event)
556 GtkMenuShell *menu_shell;
557 GtkWidget *menu_item;
559 if (event->type != GDK_BUTTON_PRESS)
562 menu_shell = GTK_MENU_SHELL (widget);
564 if (menu_shell->parent_menu_shell)
565 return gtk_widget_event (menu_shell->parent_menu_shell, (GdkEvent*) event);
567 menu_item = gtk_menu_shell_get_item (menu_shell, (GdkEvent *)event);
569 if (menu_item && _gtk_menu_item_is_selectable (menu_item) &&
570 menu_item != GTK_MENU_SHELL (menu_item->parent)->active_menu_item)
572 /* select the menu item *before* activating the shell, so submenus
573 * which might be open are closed the friendly way. If we activate
574 * (and thus grab) this menu shell first, we might get grab_broken
575 * events which will close the entire menu hierarchy. Selecting the
576 * menu item also fixes up the state as if enter_notify() would
577 * have run before (which normally selects the item).
579 if (GTK_MENU_SHELL_GET_CLASS (menu_item->parent)->submenu_placement != GTK_TOP_BOTTOM)
581 gtk_menu_shell_select_item (GTK_MENU_SHELL (menu_item->parent), menu_item);
585 if (!menu_shell->active || !menu_shell->button)
587 _gtk_menu_shell_activate (menu_shell);
589 menu_shell->button = event->button;
591 if (menu_item && _gtk_menu_item_is_selectable (menu_item) &&
592 menu_item->parent == widget &&
593 menu_item != menu_shell->active_menu_item)
595 if (GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement == GTK_TOP_BOTTOM)
597 menu_shell->activate_time = event->time;
598 gtk_menu_shell_select_item (menu_shell, menu_item);
604 widget = gtk_get_event_widget ((GdkEvent*) event);
605 if (widget == GTK_WIDGET (menu_shell))
607 gtk_menu_shell_deactivate (menu_shell);
608 g_signal_emit (menu_shell, menu_shell_signals[SELECTION_DONE], 0);
612 if (menu_item && _gtk_menu_item_is_selectable (menu_item) &&
613 GTK_MENU_ITEM (menu_item)->submenu != NULL &&
614 !GTK_WIDGET_VISIBLE (GTK_MENU_ITEM (menu_item)->submenu))
616 GtkMenuShellPrivate *priv;
618 _gtk_menu_item_popup_submenu (menu_item, FALSE);
620 priv = GTK_MENU_SHELL_GET_PRIVATE (menu_item->parent);
621 priv->activated_submenu = TRUE;
628 gtk_menu_shell_grab_broken (GtkWidget *widget,
629 GdkEventGrabBroken *event)
631 GtkMenuShell *menu_shell = GTK_MENU_SHELL (widget);
633 if (menu_shell->have_xgrab && event->grab_window == NULL)
635 /* Unset the active menu item so gtk_menu_popdown() doesn't see it.
638 gtk_menu_shell_deselect (menu_shell);
640 gtk_menu_shell_deactivate (menu_shell);
641 g_signal_emit (menu_shell, menu_shell_signals[SELECTION_DONE], 0);
648 gtk_menu_shell_button_release (GtkWidget *widget,
649 GdkEventButton *event)
651 GtkMenuShell *menu_shell = GTK_MENU_SHELL (widget);
652 GtkMenuShellPrivate *priv = GTK_MENU_SHELL_GET_PRIVATE (widget);
654 if (menu_shell->active)
656 GtkWidget *menu_item;
657 gboolean deactivate = TRUE;
659 if (menu_shell->button && (event->button != menu_shell->button))
661 menu_shell->button = 0;
662 if (menu_shell->parent_menu_shell)
663 return gtk_widget_event (menu_shell->parent_menu_shell, (GdkEvent*) event);
666 menu_shell->button = 0;
667 menu_item = gtk_menu_shell_get_item (menu_shell, (GdkEvent*) event);
669 if ((event->time - menu_shell->activate_time) > MENU_SHELL_TIMEOUT)
671 if (menu_item && (menu_shell->active_menu_item == menu_item) &&
672 _gtk_menu_item_is_selectable (menu_item))
674 GtkWidget *submenu = GTK_MENU_ITEM (menu_item)->submenu;
678 gtk_menu_shell_activate_item (menu_shell, menu_item, TRUE);
682 else if (GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement != GTK_TOP_BOTTOM ||
683 priv->activated_submenu)
686 GTimeVal *popup_time;
687 gint64 usec_since_popup = 0;
689 g_object_get (gtk_widget_get_settings (widget),
690 "gtk-menu-popdown-delay", &popdown_delay,
693 popup_time = g_object_get_data (G_OBJECT (submenu),
694 "gtk-menu-exact-popup-time");
698 GTimeVal current_time;
700 g_get_current_time (¤t_time);
702 usec_since_popup = ((gint64) current_time.tv_sec * 1000 * 1000 +
703 (gint64) current_time.tv_usec -
704 (gint64) popup_time->tv_sec * 1000 * 1000 -
705 (gint64) popup_time->tv_usec);
707 g_object_set_data (G_OBJECT (submenu),
708 "gtk-menu-exact-popup-time", NULL);
711 /* only close the submenu on click if we opened the
712 * menu explicitely (usec_since_popup == 0) or
713 * enough time has passed since it was opened by
714 * GtkMenuItem's timeout (usec_since_popup > delay).
716 if (!priv->activated_submenu &&
717 (usec_since_popup == 0 ||
718 usec_since_popup > popdown_delay * 1000))
720 _gtk_menu_item_popdown_submenu (menu_item);
724 gtk_menu_item_select (GTK_MENU_ITEM (menu_item));
730 else if (menu_item &&
731 !_gtk_menu_item_is_selectable (menu_item) &&
732 GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement != GTK_TOP_BOTTOM)
736 else if (menu_shell->parent_menu_shell)
738 menu_shell->active = TRUE;
739 gtk_widget_event (menu_shell->parent_menu_shell, (GdkEvent*) event);
743 /* If we ended up on an item with a submenu, leave the menu up.
745 if (menu_item && (menu_shell->active_menu_item == menu_item) &&
746 GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement != GTK_TOP_BOTTOM)
751 else /* a very fast press-release */
753 /* We only ever want to prevent deactivation on the first
754 * press/release. Setting the time to zero is a bit of a
755 * hack, since we could be being triggered in the first
756 * few fractions of a second after a server time wraparound.
757 * the chances of that happening are ~1/10^6, without
758 * serious harm if we lose.
760 menu_shell->activate_time = 0;
766 gtk_menu_shell_deactivate (menu_shell);
767 g_signal_emit (menu_shell, menu_shell_signals[SELECTION_DONE], 0);
770 priv->activated_submenu = FALSE;
777 gtk_menu_shell_key_press (GtkWidget *widget,
780 GtkMenuShell *menu_shell = GTK_MENU_SHELL (widget);
781 gboolean enable_mnemonics;
783 if (!menu_shell->active_menu_item && menu_shell->parent_menu_shell)
784 return gtk_widget_event (menu_shell->parent_menu_shell, (GdkEvent *)event);
786 if (gtk_bindings_activate_event (GTK_OBJECT (widget), event))
789 g_object_get (gtk_widget_get_settings (widget),
790 "gtk-enable-mnemonics", &enable_mnemonics,
793 if (enable_mnemonics)
794 return gtk_menu_shell_activate_mnemonic (menu_shell, event);
800 gtk_menu_shell_enter_notify (GtkWidget *widget,
801 GdkEventCrossing *event)
803 GtkMenuShell *menu_shell = GTK_MENU_SHELL (widget);
805 if (event->mode == GDK_CROSSING_GTK_GRAB ||
806 event->mode == GDK_CROSSING_GTK_UNGRAB ||
807 event->mode == GDK_CROSSING_STATE_CHANGED)
810 if (menu_shell->active)
812 GtkWidget *menu_item;
814 menu_item = gtk_get_event_widget ((GdkEvent*) event);
817 (GTK_IS_MENU_ITEM (menu_item) &&
818 !_gtk_menu_item_is_selectable (menu_item)))
821 if (menu_item->parent == widget &&
822 GTK_IS_MENU_ITEM (menu_item))
824 if (menu_shell->ignore_enter)
827 if (event->detail != GDK_NOTIFY_INFERIOR)
829 if (GTK_WIDGET_STATE (menu_item) != GTK_STATE_PRELIGHT)
830 gtk_menu_shell_select_item (menu_shell, menu_item);
832 /* If any mouse button is down, and there is a submenu
833 * that is not yet visible, activate it. It's sufficient
834 * to check for any button's mask (not only the one
835 * matching menu_shell->button), because there is no
836 * situation a mouse button could be pressed while
837 * entering a menu item where we wouldn't want to show
840 if ((event->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) &&
841 GTK_MENU_ITEM (menu_item)->submenu != NULL)
843 GtkMenuShellPrivate *priv;
845 priv = GTK_MENU_SHELL_GET_PRIVATE (menu_item->parent);
846 priv->activated_submenu = TRUE;
848 if (!GTK_WIDGET_VISIBLE (GTK_MENU_ITEM (menu_item)->submenu))
850 gboolean touchscreen_mode;
852 g_object_get (gtk_widget_get_settings (widget),
853 "gtk-touchscreen-mode", &touchscreen_mode,
856 if (touchscreen_mode)
857 _gtk_menu_item_popup_submenu (menu_item, TRUE);
862 else if (menu_shell->parent_menu_shell)
864 gtk_widget_event (menu_shell->parent_menu_shell, (GdkEvent*) event);
872 gtk_menu_shell_leave_notify (GtkWidget *widget,
873 GdkEventCrossing *event)
875 if (event->mode == GDK_CROSSING_GTK_GRAB ||
876 event->mode == GDK_CROSSING_GTK_GRAB ||
877 event->mode == GDK_CROSSING_STATE_CHANGED)
880 if (GTK_WIDGET_VISIBLE (widget))
882 GtkMenuShell *menu_shell = GTK_MENU_SHELL (widget);
883 GtkWidget *event_widget = gtk_get_event_widget ((GdkEvent*) event);
884 GtkMenuItem *menu_item;
886 if (!event_widget || !GTK_IS_MENU_ITEM (event_widget))
889 menu_item = GTK_MENU_ITEM (event_widget);
891 if (!_gtk_menu_item_is_selectable (event_widget))
894 if ((menu_shell->active_menu_item == event_widget) &&
895 (menu_item->submenu == NULL))
897 if ((event->detail != GDK_NOTIFY_INFERIOR) &&
898 (GTK_WIDGET_STATE (menu_item) != GTK_STATE_NORMAL))
900 gtk_menu_shell_deselect (menu_shell);
903 else if (menu_shell->parent_menu_shell)
905 gtk_widget_event (menu_shell->parent_menu_shell, (GdkEvent*) event);
913 gtk_menu_shell_screen_changed (GtkWidget *widget,
914 GdkScreen *previous_screen)
916 gtk_menu_shell_reset_key_hash (GTK_MENU_SHELL (widget));
920 gtk_menu_shell_add (GtkContainer *container,
923 gtk_menu_shell_append (GTK_MENU_SHELL (container), widget);
927 gtk_menu_shell_remove (GtkContainer *container,
930 GtkMenuShell *menu_shell = GTK_MENU_SHELL (container);
933 was_visible = GTK_WIDGET_VISIBLE (widget);
934 menu_shell->children = g_list_remove (menu_shell->children, widget);
936 if (widget == menu_shell->active_menu_item)
938 gtk_item_deselect (GTK_ITEM (menu_shell->active_menu_item));
939 menu_shell->active_menu_item = NULL;
942 gtk_widget_unparent (widget);
944 /* queue resize regardless of GTK_WIDGET_VISIBLE (container),
945 * since that's what is needed by toplevels.
948 gtk_widget_queue_resize (GTK_WIDGET (container));
952 gtk_menu_shell_forall (GtkContainer *container,
953 gboolean include_internals,
954 GtkCallback callback,
955 gpointer callback_data)
957 GtkMenuShell *menu_shell = GTK_MENU_SHELL (container);
961 children = menu_shell->children;
964 child = children->data;
965 children = children->next;
967 (* callback) (child, callback_data);
973 gtk_real_menu_shell_deactivate (GtkMenuShell *menu_shell)
975 if (menu_shell->active)
977 menu_shell->button = 0;
978 menu_shell->active = FALSE;
979 menu_shell->activate_time = 0;
981 if (menu_shell->active_menu_item)
983 gtk_menu_item_deselect (GTK_MENU_ITEM (menu_shell->active_menu_item));
984 menu_shell->active_menu_item = NULL;
987 if (menu_shell->have_grab)
989 menu_shell->have_grab = FALSE;
990 gtk_grab_remove (GTK_WIDGET (menu_shell));
992 if (menu_shell->have_xgrab)
994 GdkDisplay *display = gtk_widget_get_display (GTK_WIDGET (menu_shell));
996 menu_shell->have_xgrab = FALSE;
997 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
998 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
1004 gtk_menu_shell_is_item (GtkMenuShell *menu_shell,
1009 g_return_val_if_fail (GTK_IS_MENU_SHELL (menu_shell), FALSE);
1010 g_return_val_if_fail (child != NULL, FALSE);
1012 parent = child->parent;
1013 while (GTK_IS_MENU_SHELL (parent))
1015 if (parent == (GtkWidget*) menu_shell)
1017 parent = GTK_MENU_SHELL (parent)->parent_menu_shell;
1024 gtk_menu_shell_get_item (GtkMenuShell *menu_shell,
1027 GtkWidget *menu_item;
1029 menu_item = gtk_get_event_widget ((GdkEvent*) event);
1031 while (menu_item && !GTK_IS_MENU_ITEM (menu_item))
1032 menu_item = menu_item->parent;
1034 if (menu_item && gtk_menu_shell_is_item (menu_shell, menu_item))
1040 /* Handlers for action signals */
1043 gtk_menu_shell_select_item (GtkMenuShell *menu_shell,
1044 GtkWidget *menu_item)
1046 GtkMenuShellClass *class;
1048 g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
1049 g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
1051 class = GTK_MENU_SHELL_GET_CLASS (menu_shell);
1053 if (class->select_item &&
1054 !(menu_shell->active &&
1055 menu_shell->active_menu_item == menu_item))
1056 class->select_item (menu_shell, menu_item);
1059 void _gtk_menu_item_set_placement (GtkMenuItem *menu_item,
1060 GtkSubmenuPlacement placement);
1063 gtk_menu_shell_real_select_item (GtkMenuShell *menu_shell,
1064 GtkWidget *menu_item)
1066 GtkPackDirection pack_dir = PACK_DIRECTION (menu_shell);
1068 gtk_menu_shell_deselect (menu_shell);
1070 if (!_gtk_menu_item_is_selectable (menu_item))
1073 menu_shell->active_menu_item = menu_item;
1074 if (pack_dir == GTK_PACK_DIRECTION_TTB || pack_dir == GTK_PACK_DIRECTION_BTT)
1075 _gtk_menu_item_set_placement (GTK_MENU_ITEM (menu_shell->active_menu_item),
1078 _gtk_menu_item_set_placement (GTK_MENU_ITEM (menu_shell->active_menu_item),
1079 GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement);
1080 gtk_menu_item_select (GTK_MENU_ITEM (menu_shell->active_menu_item));
1082 /* This allows the bizarre radio buttons-with-submenus-display-history
1085 if (GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu)
1086 gtk_widget_activate (menu_shell->active_menu_item);
1090 gtk_menu_shell_deselect (GtkMenuShell *menu_shell)
1092 g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
1094 if (menu_shell->active_menu_item)
1096 gtk_menu_item_deselect (GTK_MENU_ITEM (menu_shell->active_menu_item));
1097 menu_shell->active_menu_item = NULL;
1102 gtk_menu_shell_activate_item (GtkMenuShell *menu_shell,
1103 GtkWidget *menu_item,
1104 gboolean force_deactivate)
1106 GSList *slist, *shells = NULL;
1107 gboolean deactivate = force_deactivate;
1109 g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
1110 g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
1113 deactivate = GTK_MENU_ITEM_GET_CLASS (menu_item)->hide_on_activate;
1115 g_object_ref (menu_shell);
1116 g_object_ref (menu_item);
1120 GtkMenuShell *parent_menu_shell = menu_shell;
1124 g_object_ref (parent_menu_shell);
1125 shells = g_slist_prepend (shells, parent_menu_shell);
1126 parent_menu_shell = (GtkMenuShell*) parent_menu_shell->parent_menu_shell;
1128 while (parent_menu_shell);
1129 shells = g_slist_reverse (shells);
1131 gtk_menu_shell_deactivate (menu_shell);
1133 /* flush the x-queue, so any grabs are removed and
1134 * the menu is actually taken down
1136 gdk_display_sync (gtk_widget_get_display (menu_item));
1139 gtk_widget_activate (menu_item);
1141 for (slist = shells; slist; slist = slist->next)
1143 g_signal_emit (slist->data, menu_shell_signals[SELECTION_DONE], 0);
1144 g_object_unref (slist->data);
1146 g_slist_free (shells);
1148 g_object_unref (menu_shell);
1149 g_object_unref (menu_item);
1152 /* Distance should be +/- 1 */
1154 gtk_menu_shell_real_move_selected (GtkMenuShell *menu_shell,
1157 if (menu_shell->active_menu_item)
1159 GList *node = g_list_find (menu_shell->children,
1160 menu_shell->active_menu_item);
1161 GList *start_node = node;
1162 gboolean wrap_around;
1164 g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu_shell)),
1165 "gtk-keynav-wrap-around", &wrap_around,
1171 while (node != start_node &&
1172 (!node || !_gtk_menu_item_is_selectable (node->data)))
1176 else if (wrap_around)
1177 node = menu_shell->children;
1180 gtk_widget_error_bell (GTK_WIDGET (menu_shell));
1188 while (node != start_node &&
1189 (!node || !_gtk_menu_item_is_selectable (node->data)))
1193 else if (wrap_around)
1194 node = g_list_last (menu_shell->children);
1197 gtk_widget_error_bell (GTK_WIDGET (menu_shell));
1204 gtk_menu_shell_select_item (menu_shell, node->data);
1210 /* Distance should be +/- 1 */
1212 gtk_menu_shell_move_selected (GtkMenuShell *menu_shell,
1215 gboolean handled = FALSE;
1217 g_signal_emit (menu_shell, menu_shell_signals[MOVE_SELECTED], 0,
1218 distance, &handled);
1222 * gtk_menu_shell_select_first:
1223 * @menu_shell: a #GtkMenuShell
1224 * @search_sensitive: if %TRUE, search for the first selectable
1225 * menu item, otherwise select nothing if
1226 * the first item isn't sensitive. This
1227 * should be %FALSE if the menu is being
1228 * popped up initially.
1230 * Select the first visible or selectable child of the menu shell;
1231 * don't select tearoff items unless the only item is a tearoff
1237 gtk_menu_shell_select_first (GtkMenuShell *menu_shell,
1238 gboolean search_sensitive)
1240 GtkWidget *to_select = NULL;
1243 tmp_list = menu_shell->children;
1246 GtkWidget *child = tmp_list->data;
1248 if ((!search_sensitive && GTK_WIDGET_VISIBLE (child)) ||
1249 _gtk_menu_item_is_selectable (child))
1252 if (!GTK_IS_TEAROFF_MENU_ITEM (child))
1256 tmp_list = tmp_list->next;
1260 gtk_menu_shell_select_item (menu_shell, to_select);
1264 _gtk_menu_shell_select_last (GtkMenuShell *menu_shell,
1265 gboolean search_sensitive)
1267 GtkWidget *to_select = NULL;
1270 tmp_list = g_list_last (menu_shell->children);
1273 GtkWidget *child = tmp_list->data;
1275 if ((!search_sensitive && GTK_WIDGET_VISIBLE (child)) ||
1276 _gtk_menu_item_is_selectable (child))
1279 if (!GTK_IS_TEAROFF_MENU_ITEM (child))
1283 tmp_list = tmp_list->prev;
1287 gtk_menu_shell_select_item (menu_shell, to_select);
1291 gtk_menu_shell_select_submenu_first (GtkMenuShell *menu_shell)
1293 GtkMenuItem *menu_item;
1295 if (menu_shell->active_menu_item == NULL)
1298 menu_item = GTK_MENU_ITEM (menu_shell->active_menu_item);
1300 if (menu_item->submenu)
1302 _gtk_menu_item_popup_submenu (GTK_WIDGET (menu_item), FALSE);
1303 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu_item->submenu), TRUE);
1304 if (GTK_MENU_SHELL (menu_item->submenu)->active_menu_item)
1312 gtk_real_menu_shell_move_current (GtkMenuShell *menu_shell,
1313 GtkMenuDirectionType direction)
1315 GtkMenuShell *parent_menu_shell = NULL;
1316 gboolean had_selection;
1317 gboolean touchscreen_mode;
1319 had_selection = menu_shell->active_menu_item != NULL;
1321 g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu_shell)),
1322 "gtk-touchscreen-mode", &touchscreen_mode,
1325 if (menu_shell->parent_menu_shell)
1326 parent_menu_shell = GTK_MENU_SHELL (menu_shell->parent_menu_shell);
1330 case GTK_MENU_DIR_PARENT:
1331 if (touchscreen_mode &&
1332 menu_shell->active_menu_item &&
1333 GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu &&
1334 GTK_WIDGET_VISIBLE (GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu))
1336 /* if we are on a menu item that has an open submenu but the
1337 * focus is not in that submenu (e.g. because it's empty or
1338 * has only insensitive items), close that submenu instead
1339 * of running into the code below which would close *this*
1342 _gtk_menu_item_popdown_submenu (menu_shell->active_menu_item);
1344 else if (parent_menu_shell)
1346 if (touchscreen_mode)
1348 /* close menu when returning from submenu. */
1349 _gtk_menu_item_popdown_submenu (GTK_MENU (menu_shell)->parent_menu_item);
1353 if (GTK_MENU_SHELL_GET_CLASS (parent_menu_shell)->submenu_placement ==
1354 GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement)
1355 gtk_menu_shell_deselect (menu_shell);
1358 if (PACK_DIRECTION (parent_menu_shell) == GTK_PACK_DIRECTION_LTR)
1359 gtk_menu_shell_move_selected (parent_menu_shell, -1);
1361 gtk_menu_shell_move_selected (parent_menu_shell, 1);
1362 gtk_menu_shell_select_submenu_first (parent_menu_shell);
1365 /* If there is no parent and the submenu is in the opposite direction
1366 * to the menu, then make the PARENT direction wrap around to
1367 * the bottom of the submenu.
1369 else if (menu_shell->active_menu_item &&
1370 _gtk_menu_item_is_selectable (menu_shell->active_menu_item) &&
1371 GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu)
1373 GtkMenuShell *submenu = GTK_MENU_SHELL (GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu);
1375 if (GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement !=
1376 GTK_MENU_SHELL_GET_CLASS (submenu)->submenu_placement)
1377 _gtk_menu_shell_select_last (submenu, TRUE);
1381 case GTK_MENU_DIR_CHILD:
1382 if (menu_shell->active_menu_item &&
1383 _gtk_menu_item_is_selectable (menu_shell->active_menu_item) &&
1384 GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu)
1386 if (gtk_menu_shell_select_submenu_first (menu_shell))
1390 /* Try to find a menu running the opposite direction */
1391 while (parent_menu_shell &&
1392 (GTK_MENU_SHELL_GET_CLASS (parent_menu_shell)->submenu_placement ==
1393 GTK_MENU_SHELL_GET_CLASS (menu_shell)->submenu_placement))
1395 parent_menu_shell = GTK_MENU_SHELL (parent_menu_shell->parent_menu_shell);
1398 if (parent_menu_shell)
1400 if (PACK_DIRECTION (parent_menu_shell) == GTK_PACK_DIRECTION_LTR)
1401 gtk_menu_shell_move_selected (parent_menu_shell, 1);
1403 gtk_menu_shell_move_selected (parent_menu_shell, -1);
1405 gtk_menu_shell_select_submenu_first (parent_menu_shell);
1409 case GTK_MENU_DIR_PREV:
1410 gtk_menu_shell_move_selected (menu_shell, -1);
1411 if (!had_selection &&
1412 !menu_shell->active_menu_item &&
1413 menu_shell->children)
1414 _gtk_menu_shell_select_last (menu_shell, TRUE);
1417 case GTK_MENU_DIR_NEXT:
1418 gtk_menu_shell_move_selected (menu_shell, 1);
1419 if (!had_selection &&
1420 !menu_shell->active_menu_item &&
1421 menu_shell->children)
1422 gtk_menu_shell_select_first (menu_shell, TRUE);
1428 gtk_real_menu_shell_activate_current (GtkMenuShell *menu_shell,
1429 gboolean force_hide)
1431 if (menu_shell->active_menu_item &&
1432 _gtk_menu_item_is_selectable (menu_shell->active_menu_item))
1434 if (GTK_MENU_ITEM (menu_shell->active_menu_item)->submenu == NULL)
1435 gtk_menu_shell_activate_item (menu_shell,
1436 menu_shell->active_menu_item,
1439 _gtk_menu_item_popup_submenu (menu_shell->active_menu_item, FALSE);
1444 gtk_real_menu_shell_cancel (GtkMenuShell *menu_shell)
1446 /* Unset the active menu item so gtk_menu_popdown() doesn't see it.
1448 gtk_menu_shell_deselect (menu_shell);
1450 gtk_menu_shell_deactivate (menu_shell);
1451 g_signal_emit (menu_shell, menu_shell_signals[SELECTION_DONE], 0);
1455 gtk_real_menu_shell_cycle_focus (GtkMenuShell *menu_shell,
1456 GtkDirectionType dir)
1458 while (menu_shell && !GTK_IS_MENU_BAR (menu_shell))
1460 if (menu_shell->parent_menu_shell)
1461 menu_shell = GTK_MENU_SHELL (menu_shell->parent_menu_shell);
1467 _gtk_menu_bar_cycle_focus (GTK_MENU_BAR (menu_shell), dir);
1471 _gtk_menu_shell_get_popup_delay (GtkMenuShell *menu_shell)
1473 GtkMenuShellClass *klass = GTK_MENU_SHELL_GET_CLASS (menu_shell);
1475 if (klass->get_popup_delay)
1477 return klass->get_popup_delay (menu_shell);
1482 GtkWidget *widget = GTK_WIDGET (menu_shell);
1484 g_object_get (gtk_widget_get_settings (widget),
1485 "gtk-menu-popup-delay", &popup_delay,
1493 * gtk_menu_shell_cancel:
1494 * @menu_shell: a #GtkMenuShell
1496 * Cancels the selection within the menu shell.
1501 gtk_menu_shell_cancel (GtkMenuShell *menu_shell)
1503 g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
1505 g_signal_emit (menu_shell, menu_shell_signals[CANCEL], 0);
1508 static GtkMnemonicHash *
1509 gtk_menu_shell_get_mnemonic_hash (GtkMenuShell *menu_shell,
1512 GtkMenuShellPrivate *private = GTK_MENU_SHELL_GET_PRIVATE (menu_shell);
1514 if (!private->mnemonic_hash && create)
1515 private->mnemonic_hash = _gtk_mnemonic_hash_new ();
1517 return private->mnemonic_hash;
1521 menu_shell_add_mnemonic_foreach (guint keyval,
1525 GtkKeyHash *key_hash = data;
1527 _gtk_key_hash_add_entry (key_hash, keyval, 0, GUINT_TO_POINTER (keyval));
1531 gtk_menu_shell_get_key_hash (GtkMenuShell *menu_shell,
1534 GtkMenuShellPrivate *private = GTK_MENU_SHELL_GET_PRIVATE (menu_shell);
1535 GtkWidget *widget = GTK_WIDGET (menu_shell);
1537 if (!private->key_hash && create && gtk_widget_has_screen (widget))
1539 GtkMnemonicHash *mnemonic_hash = gtk_menu_shell_get_mnemonic_hash (menu_shell, FALSE);
1540 GdkScreen *screen = gtk_widget_get_screen (widget);
1541 GdkKeymap *keymap = gdk_keymap_get_for_display (gdk_screen_get_display (screen));
1546 private->key_hash = _gtk_key_hash_new (keymap, NULL);
1548 _gtk_mnemonic_hash_foreach (mnemonic_hash,
1549 menu_shell_add_mnemonic_foreach,
1553 return private->key_hash;
1557 gtk_menu_shell_reset_key_hash (GtkMenuShell *menu_shell)
1559 GtkMenuShellPrivate *private = GTK_MENU_SHELL_GET_PRIVATE (menu_shell);
1561 if (private->key_hash)
1563 _gtk_key_hash_free (private->key_hash);
1564 private->key_hash = NULL;
1569 gtk_menu_shell_activate_mnemonic (GtkMenuShell *menu_shell,
1572 GtkMnemonicHash *mnemonic_hash;
1573 GtkKeyHash *key_hash;
1575 gboolean result = FALSE;
1577 mnemonic_hash = gtk_menu_shell_get_mnemonic_hash (menu_shell, FALSE);
1581 key_hash = gtk_menu_shell_get_key_hash (menu_shell, TRUE);
1585 entries = _gtk_key_hash_lookup (key_hash,
1586 event->hardware_keycode,
1588 gtk_accelerator_get_default_mod_mask (),
1592 result = _gtk_mnemonic_hash_activate (mnemonic_hash,
1593 GPOINTER_TO_UINT (entries->data));
1599 _gtk_menu_shell_add_mnemonic (GtkMenuShell *menu_shell,
1603 g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
1604 g_return_if_fail (GTK_IS_WIDGET (target));
1606 _gtk_mnemonic_hash_add (gtk_menu_shell_get_mnemonic_hash (menu_shell, TRUE),
1608 gtk_menu_shell_reset_key_hash (menu_shell);
1612 _gtk_menu_shell_remove_mnemonic (GtkMenuShell *menu_shell,
1616 g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
1617 g_return_if_fail (GTK_IS_WIDGET (target));
1619 _gtk_mnemonic_hash_remove (gtk_menu_shell_get_mnemonic_hash (menu_shell, TRUE),
1621 gtk_menu_shell_reset_key_hash (menu_shell);
1625 * gtk_menu_shell_get_take_focus:
1626 * @menu_shell: a #GtkMenuShell
1628 * Returns %TRUE if the menu shell will take the keyboard focus on popup.
1630 * Returns: %TRUE if the menu shell will take the keyboard focus on popup.
1635 gtk_menu_shell_get_take_focus (GtkMenuShell *menu_shell)
1637 GtkMenuShellPrivate *priv;
1639 g_return_val_if_fail (GTK_IS_MENU_SHELL (menu_shell), FALSE);
1641 priv = GTK_MENU_SHELL_GET_PRIVATE (menu_shell);
1643 return priv->take_focus;
1647 * gtk_menu_shell_set_take_focus:
1648 * @menu_shell: a #GtkMenuShell
1649 * @take_focus: %TRUE if the menu shell should take the keyboard focus on popup.
1651 * If @take_focus is %TRUE (the default) the menu shell will take the keyboard
1652 * focus so that it will receive all keyboard events which is needed to enable
1653 * keyboard navigation in menus.
1655 * Setting @take_focus to %FALSE is useful only for special applications
1656 * like virtual keyboard implementations which should not take keyboard
1659 * The @take_focus state of a menu or menu bar is automatically propagated
1660 * to submenus whenever a submenu is popped up, so you don't have to worry
1661 * about recursively setting it for your entire menu hierarchy. Only when
1662 * programmatically picking a submenu and popping it up manually, the
1663 * @take_focus property of the submenu needs to be set explicitely.
1665 * Note that setting it to %FALSE has side-effects:
1667 * If the focus is in some other app, it keeps the focus and keynav in
1668 * the menu doesn't work. Consequently, keynav on the menu will only
1669 * work if the focus is on some toplevel owned by the onscreen keyboard.
1671 * To avoid confusing the user, menus with @take_focus set to %FALSE
1672 * should not display mnemonics or accelerators, since it cannot be
1673 * guaranteed that they will work.
1675 * See also gdk_keyboard_grab()
1680 gtk_menu_shell_set_take_focus (GtkMenuShell *menu_shell,
1681 gboolean take_focus)
1683 GtkMenuShellPrivate *priv;
1685 g_return_if_fail (GTK_IS_MENU_SHELL (menu_shell));
1687 priv = GTK_MENU_SHELL_GET_PRIVATE (menu_shell);
1689 if (priv->take_focus != take_focus)
1691 priv->take_focus = take_focus;
1692 g_object_notify (G_OBJECT (menu_shell), "take-focus");
1696 #define __GTK_MENU_SHELL_C__
1697 #include "gtkaliasdef.c"