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, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 * @Short_description: A subclass of GtkMenuShell which holds GtkMenuItem widgets
29 * @See_also: #GtkMenuShell, #GtkMenu, #GtkMenuItem
31 * The #GtkMenuBar is a subclass of #GtkMenuShell which contains one or
32 * more #GtkMenuItems. The result is a standard menu bar which can hold
38 #include "gtkmenubar.h"
40 #include "gtkbindings.h"
42 #include "gtkmarshalers.h"
43 #include "gtkmenuitemprivate.h"
44 #include "gtkmenuprivate.h"
45 #include "gtkmenushellprivate.h"
46 #include "gtksettings.h"
47 #include "gtksizerequest.h"
48 #include "gtkwindow.h"
49 #include "gtkcontainerprivate.h"
51 #include "gtkprivate.h"
52 #include "gtktypebuiltins.h"
58 PROP_CHILD_PACK_DIRECTION
61 struct _GtkMenuBarPrivate
63 GtkPackDirection pack_direction;
64 GtkPackDirection child_pack_direction;
68 static void gtk_menu_bar_set_property (GObject *object,
72 static void gtk_menu_bar_get_property (GObject *object,
76 static void gtk_menu_bar_get_preferred_width (GtkWidget *widget,
79 static void gtk_menu_bar_get_preferred_height (GtkWidget *widget,
82 static void gtk_menu_bar_get_preferred_width_for_height (GtkWidget *widget,
86 static void gtk_menu_bar_get_preferred_height_for_width (GtkWidget *widget,
90 static void gtk_menu_bar_size_allocate (GtkWidget *widget,
91 GtkAllocation *allocation);
92 static gint gtk_menu_bar_draw (GtkWidget *widget,
94 static void gtk_menu_bar_hierarchy_changed (GtkWidget *widget,
95 GtkWidget *old_toplevel);
96 static gint gtk_menu_bar_get_popup_delay (GtkMenuShell *menu_shell);
97 static void gtk_menu_bar_move_current (GtkMenuShell *menu_shell,
98 GtkMenuDirectionType direction);
100 static GtkShadowType get_shadow_type (GtkMenuBar *menubar);
102 G_DEFINE_TYPE (GtkMenuBar, gtk_menu_bar, GTK_TYPE_MENU_SHELL)
105 gtk_menu_bar_class_init (GtkMenuBarClass *class)
107 GObjectClass *gobject_class;
108 GtkWidgetClass *widget_class;
109 GtkMenuShellClass *menu_shell_class;
111 GtkBindingSet *binding_set;
113 gobject_class = (GObjectClass*) class;
114 widget_class = (GtkWidgetClass*) class;
115 menu_shell_class = (GtkMenuShellClass*) class;
117 gobject_class->get_property = gtk_menu_bar_get_property;
118 gobject_class->set_property = gtk_menu_bar_set_property;
120 widget_class->get_preferred_width = gtk_menu_bar_get_preferred_width;
121 widget_class->get_preferred_height = gtk_menu_bar_get_preferred_height;
122 widget_class->get_preferred_width_for_height = gtk_menu_bar_get_preferred_width_for_height;
123 widget_class->get_preferred_height_for_width = gtk_menu_bar_get_preferred_height_for_width;
124 widget_class->size_allocate = gtk_menu_bar_size_allocate;
125 widget_class->draw = gtk_menu_bar_draw;
126 widget_class->hierarchy_changed = gtk_menu_bar_hierarchy_changed;
128 gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_MENU_BAR);
130 menu_shell_class->submenu_placement = GTK_TOP_BOTTOM;
131 menu_shell_class->get_popup_delay = gtk_menu_bar_get_popup_delay;
132 menu_shell_class->move_current = gtk_menu_bar_move_current;
134 binding_set = gtk_binding_set_by_class (class);
135 gtk_binding_entry_add_signal (binding_set,
138 GTK_TYPE_MENU_DIRECTION_TYPE,
140 gtk_binding_entry_add_signal (binding_set,
143 GTK_TYPE_MENU_DIRECTION_TYPE,
145 gtk_binding_entry_add_signal (binding_set,
148 GTK_TYPE_MENU_DIRECTION_TYPE,
150 gtk_binding_entry_add_signal (binding_set,
153 GTK_TYPE_MENU_DIRECTION_TYPE,
155 gtk_binding_entry_add_signal (binding_set,
158 GTK_TYPE_MENU_DIRECTION_TYPE,
159 GTK_MENU_DIR_PARENT);
160 gtk_binding_entry_add_signal (binding_set,
163 GTK_TYPE_MENU_DIRECTION_TYPE,
164 GTK_MENU_DIR_PARENT);
165 gtk_binding_entry_add_signal (binding_set,
168 GTK_TYPE_MENU_DIRECTION_TYPE,
170 gtk_binding_entry_add_signal (binding_set,
173 GTK_TYPE_MENU_DIRECTION_TYPE,
177 * GtkMenuBar:pack-direction:
179 * The pack direction of the menubar. It determines how
180 * menuitems are arranged in the menubar.
184 g_object_class_install_property (gobject_class,
186 g_param_spec_enum ("pack-direction",
187 P_("Pack direction"),
188 P_("The pack direction of the menubar"),
189 GTK_TYPE_PACK_DIRECTION,
190 GTK_PACK_DIRECTION_LTR,
191 GTK_PARAM_READWRITE));
194 * GtkMenuBar:child-pack-direction:
196 * The child pack direction of the menubar. It determines how
197 * the widgets contained in child menuitems are arranged.
201 g_object_class_install_property (gobject_class,
202 PROP_CHILD_PACK_DIRECTION,
203 g_param_spec_enum ("child-pack-direction",
204 P_("Child Pack direction"),
205 P_("The child pack direction of the menubar"),
206 GTK_TYPE_PACK_DIRECTION,
207 GTK_PACK_DIRECTION_LTR,
208 GTK_PARAM_READWRITE));
211 gtk_widget_class_install_style_property (widget_class,
212 g_param_spec_enum ("shadow-type",
214 P_("Style of bevel around the menubar"),
215 GTK_TYPE_SHADOW_TYPE,
217 GTK_PARAM_READABLE));
220 * GtkMenuBar:internal-padding:
222 * Amount of border space between the menubar shadow and the menu items
224 * Deprecated: 3.8: use the standard padding CSS property (through objects
225 * like #GtkStyleContext and #GtkCssProvider); the value of this style
226 * property is ignored.
228 gtk_widget_class_install_style_property (widget_class,
229 g_param_spec_int ("internal-padding",
230 P_("Internal padding"),
231 P_("Amount of border space between the menubar shadow and the menu items"),
236 G_PARAM_DEPRECATED));
238 g_type_class_add_private (gobject_class, sizeof (GtkMenuBarPrivate));
242 gtk_menu_bar_init (GtkMenuBar *menu_bar)
244 GtkStyleContext *context;
246 menu_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (menu_bar,
250 context = gtk_widget_get_style_context (GTK_WIDGET (menu_bar));
251 gtk_style_context_add_class (context, GTK_STYLE_CLASS_MENUBAR);
257 * Creates a new #GtkMenuBar
259 * Returns: the new menu bar, as a #GtkWidget
262 gtk_menu_bar_new (void)
264 return g_object_new (GTK_TYPE_MENU_BAR, NULL);
268 gtk_menu_bar_set_property (GObject *object,
273 GtkMenuBar *menubar = GTK_MENU_BAR (object);
277 case PROP_PACK_DIRECTION:
278 gtk_menu_bar_set_pack_direction (menubar, g_value_get_enum (value));
280 case PROP_CHILD_PACK_DIRECTION:
281 gtk_menu_bar_set_child_pack_direction (menubar, g_value_get_enum (value));
284 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
290 gtk_menu_bar_get_property (GObject *object,
295 GtkMenuBar *menubar = GTK_MENU_BAR (object);
299 case PROP_PACK_DIRECTION:
300 g_value_set_enum (value, gtk_menu_bar_get_pack_direction (menubar));
302 case PROP_CHILD_PACK_DIRECTION:
303 g_value_set_enum (value, gtk_menu_bar_get_child_pack_direction (menubar));
306 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
312 get_preferred_size_for_size (GtkWidget *widget,
313 GtkOrientation orientation,
318 if (orientation == GTK_ORIENTATION_HORIZONTAL)
320 gtk_widget_get_preferred_width (widget, minimum, natural);
322 gtk_widget_get_preferred_width_for_height (widget, size, minimum, natural);
325 gtk_widget_get_preferred_height (widget, minimum, natural);
327 gtk_widget_get_preferred_height_for_width (widget, size, minimum, natural);
331 gtk_menu_bar_size_request (GtkWidget *widget,
332 GtkOrientation orientation,
337 GtkMenuBar *menu_bar;
338 GtkMenuBarPrivate *priv;
339 GtkMenuShell *menu_shell;
343 gboolean use_toggle_size, use_maximize;
344 gint child_minimum, child_natural;
345 GtkStyleContext *context;
352 menu_bar = GTK_MENU_BAR (widget);
353 menu_shell = GTK_MENU_SHELL (widget);
354 priv = menu_bar->priv;
356 children = menu_shell->priv->children;
358 if (priv->child_pack_direction == GTK_PACK_DIRECTION_LTR ||
359 priv->child_pack_direction == GTK_PACK_DIRECTION_RTL)
360 use_toggle_size = (orientation == GTK_ORIENTATION_HORIZONTAL);
362 use_toggle_size = (orientation == GTK_ORIENTATION_VERTICAL);
364 if (priv->pack_direction == GTK_PACK_DIRECTION_LTR ||
365 priv->pack_direction == GTK_PACK_DIRECTION_RTL)
366 use_maximize = (orientation == GTK_ORIENTATION_VERTICAL);
368 use_maximize = (orientation == GTK_ORIENTATION_HORIZONTAL);
372 child = children->data;
373 children = children->next;
375 if (gtk_widget_get_visible (child))
377 get_preferred_size_for_size (child, orientation, size, &child_minimum, &child_natural);
383 gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
386 child_minimum += toggle_size;
387 child_natural += toggle_size;
392 *minimum = MAX (*minimum, child_minimum);
393 *natural = MAX (*natural, child_natural);
397 *minimum += child_minimum;
398 *natural += child_natural;
403 context = gtk_widget_get_style_context (widget);
404 flags = gtk_widget_get_state_flags (widget);
405 gtk_style_context_get_padding (context, flags, &border);
407 if (orientation == GTK_ORIENTATION_HORIZONTAL)
409 *minimum += border.left + border.right;
410 *natural += border.left + border.right;
414 *minimum += border.top + border.bottom;
415 *natural += border.top + border.bottom;
418 border_width = gtk_container_get_border_width (GTK_CONTAINER (menu_bar));
419 *minimum += border_width * 2;
420 *natural += border_width * 2;
422 if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
424 gtk_style_context_get_border (context, flags, &border);
426 if (orientation == GTK_ORIENTATION_HORIZONTAL)
428 *minimum += border.left + border.right;
429 *natural += border.left + border.right;
433 *minimum += border.top + border.bottom;
434 *natural += border.top + border.bottom;
440 gtk_menu_bar_get_preferred_width (GtkWidget *widget,
444 gtk_menu_bar_size_request (widget, GTK_ORIENTATION_HORIZONTAL, -1, minimum, natural);
448 gtk_menu_bar_get_preferred_height (GtkWidget *widget,
452 gtk_menu_bar_size_request (widget, GTK_ORIENTATION_VERTICAL, -1, minimum, natural);
456 gtk_menu_bar_get_preferred_width_for_height (GtkWidget *widget,
461 gtk_menu_bar_size_request (widget, GTK_ORIENTATION_HORIZONTAL, height, minimum, natural);
465 gtk_menu_bar_get_preferred_height_for_width (GtkWidget *widget,
470 gtk_menu_bar_size_request (widget, GTK_ORIENTATION_VERTICAL, width, minimum, natural);
474 gtk_menu_bar_size_allocate (GtkWidget *widget,
475 GtkAllocation *allocation)
477 GtkMenuBar *menu_bar;
478 GtkMenuShell *menu_shell;
479 GtkMenuBarPrivate *priv;
482 GtkAllocation remaining_space;
484 GArray *requested_sizes;
488 g_return_if_fail (GTK_IS_MENU_BAR (widget));
489 g_return_if_fail (allocation != NULL);
491 menu_bar = GTK_MENU_BAR (widget);
492 menu_shell = GTK_MENU_SHELL (widget);
493 priv = menu_bar->priv;
495 gtk_widget_set_allocation (widget, allocation);
497 if (gtk_widget_get_realized (widget))
498 gdk_window_move_resize (gtk_widget_get_window (widget),
499 allocation->x, allocation->y,
500 allocation->width, allocation->height);
502 if (menu_shell->priv->children)
504 GtkStyleContext *context;
508 context = gtk_widget_get_style_context (widget);
509 flags = gtk_widget_get_state_flags (widget);
510 gtk_style_context_get_padding (context, flags, &border);
512 border_width = gtk_container_get_border_width (GTK_CONTAINER (menu_bar));
514 remaining_space.x = (border_width + border.left);
515 remaining_space.y = (border_width + border.top);
516 remaining_space.width = allocation->width -
517 2 * (border_width) - border.left - border.right;
518 remaining_space.height = allocation->height -
519 2 * (border_width) - border.top - border.bottom;
521 if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
523 gtk_style_context_get_border (context, flags, &border);
525 remaining_space.x += border.left;
526 remaining_space.y += border.top;
527 remaining_space.width -= border.left + border.right;
528 remaining_space.height -= border.top + border.bottom;
531 requested_sizes = g_array_new (FALSE, FALSE, sizeof (GtkRequestedSize));
533 if (priv->pack_direction == GTK_PACK_DIRECTION_LTR ||
534 priv->pack_direction == GTK_PACK_DIRECTION_RTL)
536 int size = remaining_space.width;
537 gboolean ltr = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) == (priv->pack_direction == GTK_PACK_DIRECTION_LTR);
539 for (children = menu_shell->priv->children; children; children = children->next)
541 GtkRequestedSize request;
542 child = children->data;
544 if (!gtk_widget_get_visible (child))
547 request.data = child;
548 gtk_widget_get_preferred_width_for_height (child,
549 remaining_space.height,
550 &request.minimum_size,
551 &request.natural_size);
552 gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
554 request.minimum_size += toggle_size;
555 request.natural_size += toggle_size;
557 gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child), toggle_size);
559 g_array_append_val (requested_sizes, request);
561 size -= request.minimum_size;
564 size = gtk_distribute_natural_allocation (size,
565 requested_sizes->len,
566 (GtkRequestedSize *) requested_sizes->data);
568 for (i = 0; i < requested_sizes->len; i++)
570 GtkAllocation child_allocation = remaining_space;
571 GtkRequestedSize *request = &g_array_index (requested_sizes, GtkRequestedSize, i);
573 child_allocation.width = request->minimum_size;
574 remaining_space.width -= request->minimum_size;
576 if (i + 1 == requested_sizes->len && GTK_IS_MENU_ITEM (request->data) &&
577 GTK_MENU_ITEM (request->data)->priv->right_justify)
581 remaining_space.x += request->minimum_size;
583 child_allocation.x += remaining_space.width;
585 gtk_widget_size_allocate (request->data, &child_allocation);
590 int size = remaining_space.height;
591 gboolean ttb = (priv->pack_direction == GTK_PACK_DIRECTION_TTB);
593 for (children = menu_shell->priv->children; children; children = children->next)
595 GtkRequestedSize request;
596 child = children->data;
598 if (!gtk_widget_get_visible (child))
601 request.data = child;
602 gtk_widget_get_preferred_height_for_width (child,
603 remaining_space.width,
604 &request.minimum_size,
605 &request.natural_size);
606 gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
608 request.minimum_size += toggle_size;
609 request.natural_size += toggle_size;
611 gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child), toggle_size);
613 g_array_append_val (requested_sizes, request);
615 size -= request.minimum_size;
618 size = gtk_distribute_natural_allocation (size,
619 requested_sizes->len,
620 (GtkRequestedSize *) requested_sizes->data);
622 for (i = 0; i < requested_sizes->len; i++)
624 GtkAllocation child_allocation = remaining_space;
625 GtkRequestedSize *request = &g_array_index (requested_sizes, GtkRequestedSize, i);
627 child_allocation.height = request->minimum_size;
628 remaining_space.height -= request->minimum_size;
630 if (i + 1 == requested_sizes->len && GTK_IS_MENU_ITEM (request->data) &&
631 GTK_MENU_ITEM (request->data)->priv->right_justify)
635 remaining_space.y += request->minimum_size;
637 child_allocation.y += remaining_space.height;
639 gtk_widget_size_allocate (request->data, &child_allocation);
643 g_array_free (requested_sizes, TRUE);
648 gtk_menu_bar_draw (GtkWidget *widget,
651 GtkStyleContext *context;
654 border = gtk_container_get_border_width (GTK_CONTAINER (widget));
655 context = gtk_widget_get_style_context (widget);
657 gtk_render_background (context, cr,
659 gtk_widget_get_allocated_width (widget) - border * 2,
660 gtk_widget_get_allocated_height (widget) - border * 2);
662 if (get_shadow_type (GTK_MENU_BAR (widget)) != GTK_SHADOW_NONE)
663 gtk_render_frame (context, cr,
665 gtk_widget_get_allocated_width (widget) - border * 2,
666 gtk_widget_get_allocated_height (widget) - border * 2);
668 GTK_WIDGET_CLASS (gtk_menu_bar_parent_class)->draw (widget, cr);
674 get_menu_bars (GtkWindow *window)
676 return g_object_get_data (G_OBJECT (window), "gtk-menu-bar-list");
680 get_viewable_menu_bars (GtkWindow *window)
683 GList *viewable_menu_bars = NULL;
685 for (menu_bars = get_menu_bars (window);
687 menu_bars = menu_bars->next)
689 GtkWidget *widget = menu_bars->data;
690 gboolean viewable = TRUE;
694 if (!gtk_widget_get_mapped (widget))
697 widget = gtk_widget_get_parent (widget);
701 viewable_menu_bars = g_list_prepend (viewable_menu_bars, menu_bars->data);
704 return g_list_reverse (viewable_menu_bars);
708 set_menu_bars (GtkWindow *window,
711 g_object_set_data (G_OBJECT (window), I_("gtk-menu-bar-list"), menubars);
715 window_key_press_handler (GtkWidget *widget,
720 gboolean retval = FALSE;
722 g_object_get (gtk_widget_get_settings (widget),
723 "gtk-menu-bar-accel", &accel,
729 GdkModifierType mods = 0;
731 gtk_accelerator_parse (accel, &keyval, &mods);
734 g_warning ("Failed to parse menu bar accelerator '%s'\n", accel);
736 /* FIXME this is wrong, needs to be in the global accel resolution
737 * thing, to properly consider i18n etc., but that probably requires
738 * AccelGroup changes etc.
740 if (event->keyval == keyval &&
741 ((event->state & gtk_accelerator_get_default_mod_mask ()) ==
742 (mods & gtk_accelerator_get_default_mod_mask ())))
744 GList *tmp_menubars = get_viewable_menu_bars (GTK_WINDOW (widget));
747 menubars = _gtk_container_focus_sort (GTK_CONTAINER (widget), tmp_menubars,
748 GTK_DIR_TAB_FORWARD, NULL);
749 g_list_free (tmp_menubars);
753 GtkMenuShell *menu_shell = GTK_MENU_SHELL (menubars->data);
755 _gtk_menu_shell_set_keyboard_mode (menu_shell, TRUE);
756 gtk_menu_shell_select_first (menu_shell, FALSE);
758 g_list_free (menubars);
771 add_to_window (GtkWindow *window,
774 GList *menubars = get_menu_bars (window);
778 g_signal_connect (window,
780 G_CALLBACK (window_key_press_handler),
784 set_menu_bars (window, g_list_prepend (menubars, menubar));
788 remove_from_window (GtkWindow *window,
791 GList *menubars = get_menu_bars (window);
793 menubars = g_list_remove (menubars, menubar);
797 g_signal_handlers_disconnect_by_func (window,
798 window_key_press_handler,
802 set_menu_bars (window, menubars);
806 gtk_menu_bar_hierarchy_changed (GtkWidget *widget,
807 GtkWidget *old_toplevel)
812 menubar = GTK_MENU_BAR (widget);
814 toplevel = gtk_widget_get_toplevel (widget);
817 remove_from_window (GTK_WINDOW (old_toplevel), menubar);
819 if (gtk_widget_is_toplevel (toplevel))
820 add_to_window (GTK_WINDOW (toplevel), menubar);
824 * _gtk_menu_bar_cycle_focus:
825 * @menubar: a #GtkMenuBar
826 * @dir: direction in which to cycle the focus
828 * Move the focus between menubars in the toplevel.
831 _gtk_menu_bar_cycle_focus (GtkMenuBar *menubar,
832 GtkDirectionType dir)
834 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menubar));
835 GtkMenuItem *to_activate = NULL;
837 if (gtk_widget_is_toplevel (toplevel))
839 GList *tmp_menubars = get_viewable_menu_bars (GTK_WINDOW (toplevel));
843 menubars = _gtk_container_focus_sort (GTK_CONTAINER (toplevel), tmp_menubars,
844 dir, GTK_WIDGET (menubar));
845 g_list_free (tmp_menubars);
849 current = g_list_find (menubars, menubar);
851 if (current && current->next)
853 GtkMenuShell *new_menushell = GTK_MENU_SHELL (current->next->data);
854 if (new_menushell->priv->children)
855 to_activate = new_menushell->priv->children->data;
859 g_list_free (menubars);
862 gtk_menu_shell_cancel (GTK_MENU_SHELL (menubar));
865 g_signal_emit_by_name (to_activate, "activate_item");
869 get_shadow_type (GtkMenuBar *menubar)
871 GtkShadowType shadow_type = GTK_SHADOW_OUT;
873 gtk_widget_style_get (GTK_WIDGET (menubar),
874 "shadow-type", &shadow_type,
881 gtk_menu_bar_get_popup_delay (GtkMenuShell *menu_shell)
885 g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu_shell)),
886 "gtk-menu-bar-popup-delay", &popup_delay,
893 gtk_menu_bar_move_current (GtkMenuShell *menu_shell,
894 GtkMenuDirectionType direction)
896 GtkMenuBar *menubar = GTK_MENU_BAR (menu_shell);
897 GtkTextDirection text_dir;
898 GtkPackDirection pack_dir;
900 text_dir = gtk_widget_get_direction (GTK_WIDGET (menubar));
901 pack_dir = gtk_menu_bar_get_pack_direction (menubar);
903 if (pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL)
905 if ((text_dir == GTK_TEXT_DIR_RTL) == (pack_dir == GTK_PACK_DIRECTION_LTR))
909 case GTK_MENU_DIR_PREV:
910 direction = GTK_MENU_DIR_NEXT;
912 case GTK_MENU_DIR_NEXT:
913 direction = GTK_MENU_DIR_PREV;
923 case GTK_MENU_DIR_PARENT:
924 if ((text_dir == GTK_TEXT_DIR_LTR) == (pack_dir == GTK_PACK_DIRECTION_TTB))
925 direction = GTK_MENU_DIR_PREV;
927 direction = GTK_MENU_DIR_NEXT;
929 case GTK_MENU_DIR_CHILD:
930 if ((text_dir == GTK_TEXT_DIR_LTR) == (pack_dir == GTK_PACK_DIRECTION_TTB))
931 direction = GTK_MENU_DIR_NEXT;
933 direction = GTK_MENU_DIR_PREV;
935 case GTK_MENU_DIR_PREV:
936 if (text_dir == GTK_TEXT_DIR_RTL)
937 direction = GTK_MENU_DIR_CHILD;
939 direction = GTK_MENU_DIR_PARENT;
941 case GTK_MENU_DIR_NEXT:
942 if (text_dir == GTK_TEXT_DIR_RTL)
943 direction = GTK_MENU_DIR_PARENT;
945 direction = GTK_MENU_DIR_CHILD;
951 GTK_MENU_SHELL_CLASS (gtk_menu_bar_parent_class)->move_current (menu_shell, direction);
955 * gtk_menu_bar_get_pack_direction:
956 * @menubar: a #GtkMenuBar
958 * Retrieves the current pack direction of the menubar.
959 * See gtk_menu_bar_set_pack_direction().
961 * Return value: the pack direction
966 gtk_menu_bar_get_pack_direction (GtkMenuBar *menubar)
968 g_return_val_if_fail (GTK_IS_MENU_BAR (menubar),
969 GTK_PACK_DIRECTION_LTR);
971 return menubar->priv->pack_direction;
975 * gtk_menu_bar_set_pack_direction:
976 * @menubar: a #GtkMenuBar
977 * @pack_dir: a new #GtkPackDirection
979 * Sets how items should be packed inside a menubar.
984 gtk_menu_bar_set_pack_direction (GtkMenuBar *menubar,
985 GtkPackDirection pack_dir)
987 GtkMenuBarPrivate *priv;
990 g_return_if_fail (GTK_IS_MENU_BAR (menubar));
992 priv = menubar->priv;
994 if (priv->pack_direction != pack_dir)
996 priv->pack_direction = pack_dir;
998 gtk_widget_queue_resize (GTK_WIDGET (menubar));
1000 for (l = GTK_MENU_SHELL (menubar)->priv->children; l; l = l->next)
1001 gtk_widget_queue_resize (GTK_WIDGET (l->data));
1003 g_object_notify (G_OBJECT (menubar), "pack-direction");
1008 * gtk_menu_bar_get_child_pack_direction:
1009 * @menubar: a #GtkMenuBar
1011 * Retrieves the current child pack direction of the menubar.
1012 * See gtk_menu_bar_set_child_pack_direction().
1014 * Return value: the child pack direction
1019 gtk_menu_bar_get_child_pack_direction (GtkMenuBar *menubar)
1021 g_return_val_if_fail (GTK_IS_MENU_BAR (menubar),
1022 GTK_PACK_DIRECTION_LTR);
1024 return menubar->priv->child_pack_direction;
1028 * gtk_menu_bar_set_child_pack_direction:
1029 * @menubar: a #GtkMenuBar
1030 * @child_pack_dir: a new #GtkPackDirection
1032 * Sets how widgets should be packed inside the children of a menubar.
1037 gtk_menu_bar_set_child_pack_direction (GtkMenuBar *menubar,
1038 GtkPackDirection child_pack_dir)
1040 GtkMenuBarPrivate *priv;
1043 g_return_if_fail (GTK_IS_MENU_BAR (menubar));
1045 priv = menubar->priv;
1047 if (priv->child_pack_direction != child_pack_dir)
1049 priv->child_pack_direction = child_pack_dir;
1051 gtk_widget_queue_resize (GTK_WIDGET (menubar));
1053 for (l = GTK_MENU_SHELL (menubar)->priv->children; l; l = l->next)
1054 gtk_widget_queue_resize (GTK_WIDGET (l->data));
1056 g_object_notify (G_OBJECT (menubar), "child-pack-direction");
1061 * gtk_menu_bar_new_from_model:
1062 * @model: a #GMenuModel
1064 * Creates a new #GtkMenuBar and populates it with menu items
1065 * and submenus according to @model.
1067 * The created menu items are connected to actions found in the
1068 * #GtkApplicationWindow to which the menu bar belongs - typically
1069 * by means of being contained within the #GtkApplicationWindows
1072 * Returns: a new #GtkMenuBar
1077 gtk_menu_bar_new_from_model (GMenuModel *model)
1081 g_return_val_if_fail (G_IS_MENU_MODEL (model), NULL);
1083 menubar = gtk_menu_bar_new ();
1084 gtk_menu_shell_bind_model (GTK_MENU_SHELL (menubar), model, NULL, FALSE);