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/.
30 * @Short_description: A subclass of GtkMenuShell which holds GtkMenuItem widgets
31 * @See_also: #GtkMenuShell, #GtkMenu, #GtkMenuItem
33 * The #GtkMenuBar is a subclass of #GtkMenuShell which contains one or
34 * more #GtkMenuItems. The result is a standard menu bar which can hold
40 #include "gtkmenubar.h"
42 #include "gtkbindings.h"
44 #include "gtkmarshalers.h"
45 #include "gtkmenuitemprivate.h"
46 #include "gtkmenuprivate.h"
47 #include "gtkmenushellprivate.h"
48 #include "gtksettings.h"
49 #include "gtksizerequest.h"
50 #include "gtkwindow.h"
52 #include "gtkprivate.h"
53 #include "gtktypebuiltins.h"
55 #define BORDER_SPACING 0
56 #define DEFAULT_IPADDING 1
62 PROP_CHILD_PACK_DIRECTION
65 struct _GtkMenuBarPrivate
67 GtkPackDirection pack_direction;
68 GtkPackDirection child_pack_direction;
72 static void gtk_menu_bar_set_property (GObject *object,
76 static void gtk_menu_bar_get_property (GObject *object,
80 static void gtk_menu_bar_get_preferred_width (GtkWidget *widget,
83 static void gtk_menu_bar_get_preferred_height (GtkWidget *widget,
86 static void gtk_menu_bar_size_allocate (GtkWidget *widget,
87 GtkAllocation *allocation);
88 static gint gtk_menu_bar_draw (GtkWidget *widget,
90 static void gtk_menu_bar_hierarchy_changed (GtkWidget *widget,
91 GtkWidget *old_toplevel);
92 static gint gtk_menu_bar_get_popup_delay (GtkMenuShell *menu_shell);
93 static void gtk_menu_bar_move_current (GtkMenuShell *menu_shell,
94 GtkMenuDirectionType direction);
96 static GtkShadowType get_shadow_type (GtkMenuBar *menubar);
98 G_DEFINE_TYPE (GtkMenuBar, gtk_menu_bar, GTK_TYPE_MENU_SHELL)
101 gtk_menu_bar_class_init (GtkMenuBarClass *class)
103 GObjectClass *gobject_class;
104 GtkWidgetClass *widget_class;
105 GtkMenuShellClass *menu_shell_class;
107 GtkBindingSet *binding_set;
109 gobject_class = (GObjectClass*) class;
110 widget_class = (GtkWidgetClass*) class;
111 menu_shell_class = (GtkMenuShellClass*) class;
113 gobject_class->get_property = gtk_menu_bar_get_property;
114 gobject_class->set_property = gtk_menu_bar_set_property;
116 widget_class->get_preferred_width = gtk_menu_bar_get_preferred_width;
117 widget_class->get_preferred_height = gtk_menu_bar_get_preferred_height;
118 widget_class->size_allocate = gtk_menu_bar_size_allocate;
119 widget_class->draw = gtk_menu_bar_draw;
120 widget_class->hierarchy_changed = gtk_menu_bar_hierarchy_changed;
122 menu_shell_class->submenu_placement = GTK_TOP_BOTTOM;
123 menu_shell_class->get_popup_delay = gtk_menu_bar_get_popup_delay;
124 menu_shell_class->move_current = gtk_menu_bar_move_current;
126 binding_set = gtk_binding_set_by_class (class);
127 gtk_binding_entry_add_signal (binding_set,
130 GTK_TYPE_MENU_DIRECTION_TYPE,
132 gtk_binding_entry_add_signal (binding_set,
135 GTK_TYPE_MENU_DIRECTION_TYPE,
137 gtk_binding_entry_add_signal (binding_set,
140 GTK_TYPE_MENU_DIRECTION_TYPE,
142 gtk_binding_entry_add_signal (binding_set,
145 GTK_TYPE_MENU_DIRECTION_TYPE,
147 gtk_binding_entry_add_signal (binding_set,
150 GTK_TYPE_MENU_DIRECTION_TYPE,
151 GTK_MENU_DIR_PARENT);
152 gtk_binding_entry_add_signal (binding_set,
155 GTK_TYPE_MENU_DIRECTION_TYPE,
156 GTK_MENU_DIR_PARENT);
157 gtk_binding_entry_add_signal (binding_set,
160 GTK_TYPE_MENU_DIRECTION_TYPE,
162 gtk_binding_entry_add_signal (binding_set,
165 GTK_TYPE_MENU_DIRECTION_TYPE,
169 * GtkMenuBar:pack-direction:
171 * The pack direction of the menubar. It determines how
172 * menuitems are arranged in the menubar.
176 g_object_class_install_property (gobject_class,
178 g_param_spec_enum ("pack-direction",
179 P_("Pack direction"),
180 P_("The pack direction of the menubar"),
181 GTK_TYPE_PACK_DIRECTION,
182 GTK_PACK_DIRECTION_LTR,
183 GTK_PARAM_READWRITE));
186 * GtkMenuBar:child-pack-direction:
188 * The child pack direction of the menubar. It determines how
189 * the widgets contained in child menuitems are arranged.
193 g_object_class_install_property (gobject_class,
194 PROP_CHILD_PACK_DIRECTION,
195 g_param_spec_enum ("child-pack-direction",
196 P_("Child Pack direction"),
197 P_("The child pack direction of the menubar"),
198 GTK_TYPE_PACK_DIRECTION,
199 GTK_PACK_DIRECTION_LTR,
200 GTK_PARAM_READWRITE));
203 gtk_widget_class_install_style_property (widget_class,
204 g_param_spec_enum ("shadow-type",
206 P_("Style of bevel around the menubar"),
207 GTK_TYPE_SHADOW_TYPE,
209 GTK_PARAM_READABLE));
211 gtk_widget_class_install_style_property (widget_class,
212 g_param_spec_int ("internal-padding",
213 P_("Internal padding"),
214 P_("Amount of border space between the menubar shadow and the menu items"),
218 GTK_PARAM_READABLE));
220 g_type_class_add_private (gobject_class, sizeof (GtkMenuBarPrivate));
224 gtk_menu_bar_init (GtkMenuBar *menu_bar)
226 GtkStyleContext *context;
228 menu_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (menu_bar,
232 context = gtk_widget_get_style_context (GTK_WIDGET (menu_bar));
233 gtk_style_context_add_class (context, GTK_STYLE_CLASS_MENUBAR);
239 * Creates a new #GtkMenuBar
241 * Returns: the new menu bar, as a #GtkWidget
244 gtk_menu_bar_new (void)
246 return g_object_new (GTK_TYPE_MENU_BAR, NULL);
250 gtk_menu_bar_set_property (GObject *object,
255 GtkMenuBar *menubar = GTK_MENU_BAR (object);
259 case PROP_PACK_DIRECTION:
260 gtk_menu_bar_set_pack_direction (menubar, g_value_get_enum (value));
262 case PROP_CHILD_PACK_DIRECTION:
263 gtk_menu_bar_set_child_pack_direction (menubar, g_value_get_enum (value));
266 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
272 gtk_menu_bar_get_property (GObject *object,
277 GtkMenuBar *menubar = GTK_MENU_BAR (object);
281 case PROP_PACK_DIRECTION:
282 g_value_set_enum (value, gtk_menu_bar_get_pack_direction (menubar));
284 case PROP_CHILD_PACK_DIRECTION:
285 g_value_set_enum (value, gtk_menu_bar_get_child_pack_direction (menubar));
288 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
294 gtk_menu_bar_size_request (GtkWidget *widget,
295 GtkOrientation orientation,
299 GtkMenuBar *menu_bar;
300 GtkMenuBarPrivate *priv;
301 GtkMenuShell *menu_shell;
304 GtkRequisition child_requisition;
305 GtkRequisition requisition;
308 gboolean use_toggle_size;
310 requisition.width = 0;
311 requisition.height = 0;
313 menu_bar = GTK_MENU_BAR (widget);
314 menu_shell = GTK_MENU_SHELL (widget);
315 priv = menu_bar->priv;
317 children = menu_shell->priv->children;
319 if (priv->child_pack_direction == GTK_PACK_DIRECTION_LTR ||
320 priv->child_pack_direction == GTK_PACK_DIRECTION_RTL)
321 use_toggle_size = (orientation == GTK_ORIENTATION_HORIZONTAL);
323 use_toggle_size = (orientation == GTK_ORIENTATION_VERTICAL);
327 child = children->data;
328 children = children->next;
330 if (gtk_widget_get_visible (child))
332 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
338 gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
341 child_requisition.width += toggle_size;
342 child_requisition.height += toggle_size;
345 if (priv->pack_direction == GTK_PACK_DIRECTION_LTR ||
346 priv->pack_direction == GTK_PACK_DIRECTION_RTL)
348 requisition.width += child_requisition.width;
349 requisition.height = MAX (requisition.height, child_requisition.height);
353 requisition.width = MAX (requisition.width, child_requisition.width);
354 requisition.height += child_requisition.height;
359 gtk_widget_style_get (widget, "internal-padding", &ipadding, NULL);
361 border_width = gtk_container_get_border_width (GTK_CONTAINER (menu_bar));
362 requisition.width += (border_width +
365 requisition.height += (border_width +
369 if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
371 GtkStyleContext *context;
374 context = gtk_widget_get_style_context (widget);
376 gtk_style_context_get (context, 0,
377 "border-width", &border,
380 requisition.width += border->left + border->right;
381 requisition.height += border->top + border->bottom;
382 gtk_border_free (border);
385 if (orientation == GTK_ORIENTATION_HORIZONTAL)
386 *minimum = *natural = requisition.width;
388 *minimum = *natural = requisition.height;
392 gtk_menu_bar_get_preferred_width (GtkWidget *widget,
396 gtk_menu_bar_size_request (widget, GTK_ORIENTATION_HORIZONTAL, minimum, natural);
400 gtk_menu_bar_get_preferred_height (GtkWidget *widget,
404 gtk_menu_bar_size_request (widget, GTK_ORIENTATION_VERTICAL, minimum, natural);
408 gtk_menu_bar_size_allocate (GtkWidget *widget,
409 GtkAllocation *allocation)
411 GtkMenuBar *menu_bar;
412 GtkMenuShell *menu_shell;
413 GtkMenuBarPrivate *priv;
416 GtkAllocation child_allocation;
417 GtkRequisition child_requisition;
419 GtkTextDirection direction;
424 g_return_if_fail (GTK_IS_MENU_BAR (widget));
425 g_return_if_fail (allocation != NULL);
427 menu_bar = GTK_MENU_BAR (widget);
428 menu_shell = GTK_MENU_SHELL (widget);
429 priv = menu_bar->priv;
431 direction = gtk_widget_get_direction (widget);
433 gtk_widget_set_allocation (widget, allocation);
435 if (gtk_widget_get_realized (widget))
436 gdk_window_move_resize (gtk_widget_get_window (widget),
437 allocation->x, allocation->y,
438 allocation->width, allocation->height);
440 gtk_widget_style_get (widget, "internal-padding", &ipadding, NULL);
442 if (menu_shell->priv->children)
444 border_width = gtk_container_get_border_width (GTK_CONTAINER (menu_bar));
445 child_allocation.x = (border_width +
448 child_allocation.y = (border_width +
451 if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
453 GtkStyleContext *context;
456 context = gtk_widget_get_style_context (widget);
457 gtk_style_context_get (context, 0,
458 "border-width", &border,
461 child_allocation.x += border->left;
462 child_allocation.y += border->top;
464 gtk_border_free (border);
467 if (priv->pack_direction == GTK_PACK_DIRECTION_LTR ||
468 priv->pack_direction == GTK_PACK_DIRECTION_RTL)
470 child_allocation.height = MAX (1, (gint)allocation->height - child_allocation.y * 2);
472 offset = child_allocation.x; /* Window edge to menubar start */
473 ltr_x = child_allocation.x;
475 children = menu_shell->priv->children;
480 child = children->data;
481 children = children->next;
483 gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
485 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
487 if (priv->child_pack_direction == GTK_PACK_DIRECTION_LTR ||
488 priv->child_pack_direction == GTK_PACK_DIRECTION_RTL)
489 child_requisition.width += toggle_size;
491 child_requisition.height += toggle_size;
493 /* Support for the right justified help menu */
494 if (children == NULL &&
495 GTK_IS_MENU_ITEM (child) &&
496 GTK_MENU_ITEM (child)->priv->right_justify)
498 ltr_x = allocation->width -
499 child_requisition.width - offset;
501 if (gtk_widget_get_visible (child))
503 if ((direction == GTK_TEXT_DIR_LTR) == (priv->pack_direction == GTK_PACK_DIRECTION_LTR))
504 child_allocation.x = ltr_x;
506 child_allocation.x = allocation->width -
507 child_requisition.width - ltr_x;
509 child_allocation.width = child_requisition.width;
511 gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child),
513 gtk_widget_size_allocate (child, &child_allocation);
515 ltr_x += child_allocation.width;
521 child_allocation.width = MAX (1, (gint)allocation->width - child_allocation.x * 2);
523 offset = child_allocation.y; /* Window edge to menubar start */
524 ltr_y = child_allocation.y;
526 children = menu_shell->priv->children;
531 child = children->data;
532 children = children->next;
534 gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
536 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
538 if (priv->child_pack_direction == GTK_PACK_DIRECTION_LTR ||
539 priv->child_pack_direction == GTK_PACK_DIRECTION_RTL)
540 child_requisition.width += toggle_size;
542 child_requisition.height += toggle_size;
544 /* Support for the right justified help menu */
545 if (children == NULL &&
546 GTK_IS_MENU_ITEM (child) &&
547 GTK_MENU_ITEM (child)->priv->right_justify)
549 ltr_y = allocation->height -
550 child_requisition.height - offset;
552 if (gtk_widget_get_visible (child))
554 if ((direction == GTK_TEXT_DIR_LTR) ==
555 (priv->pack_direction == GTK_PACK_DIRECTION_TTB))
556 child_allocation.y = ltr_y;
558 child_allocation.y = allocation->height -
559 child_requisition.height - ltr_y;
560 child_allocation.height = child_requisition.height;
562 gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child),
564 gtk_widget_size_allocate (child, &child_allocation);
566 ltr_y += child_allocation.height;
574 gtk_menu_bar_draw (GtkWidget *widget,
577 GtkStyleContext *context;
581 border = gtk_container_get_border_width (GTK_CONTAINER (widget));
582 context = gtk_widget_get_style_context (widget);
584 state = gtk_widget_get_state_flags (widget);
585 gtk_style_context_set_state (context, state);
587 if (get_shadow_type (GTK_MENU_BAR (widget)) != GTK_SHADOW_NONE)
588 gtk_render_background (context, cr,
590 gtk_widget_get_allocated_width (widget) - border * 2,
591 gtk_widget_get_allocated_height (widget) - border * 2);
593 gtk_render_frame (context, cr,
595 gtk_widget_get_allocated_width (widget) - border * 2,
596 gtk_widget_get_allocated_height (widget) - border * 2);
598 GTK_WIDGET_CLASS (gtk_menu_bar_parent_class)->draw (widget, cr);
604 get_menu_bars (GtkWindow *window)
606 return g_object_get_data (G_OBJECT (window), "gtk-menu-bar-list");
610 get_viewable_menu_bars (GtkWindow *window)
613 GList *viewable_menu_bars = NULL;
615 for (menu_bars = get_menu_bars (window);
617 menu_bars = menu_bars->next)
619 GtkWidget *widget = menu_bars->data;
620 gboolean viewable = TRUE;
624 if (!gtk_widget_get_mapped (widget))
627 widget = gtk_widget_get_parent (widget);
631 viewable_menu_bars = g_list_prepend (viewable_menu_bars, menu_bars->data);
634 return g_list_reverse (viewable_menu_bars);
638 set_menu_bars (GtkWindow *window,
641 g_object_set_data (G_OBJECT (window), I_("gtk-menu-bar-list"), menubars);
645 window_key_press_handler (GtkWidget *widget,
650 gboolean retval = FALSE;
652 g_object_get (gtk_widget_get_settings (widget),
653 "gtk-menu-bar-accel", &accel,
659 GdkModifierType mods = 0;
661 gtk_accelerator_parse (accel, &keyval, &mods);
664 g_warning ("Failed to parse menu bar accelerator '%s'\n", accel);
666 /* FIXME this is wrong, needs to be in the global accel resolution
667 * thing, to properly consider i18n etc., but that probably requires
668 * AccelGroup changes etc.
670 if (event->keyval == keyval &&
671 ((event->state & gtk_accelerator_get_default_mod_mask ()) ==
672 (mods & gtk_accelerator_get_default_mod_mask ())))
674 GList *tmp_menubars = get_viewable_menu_bars (GTK_WINDOW (widget));
677 menubars = _gtk_container_focus_sort (GTK_CONTAINER (widget), tmp_menubars,
678 GTK_DIR_TAB_FORWARD, NULL);
679 g_list_free (tmp_menubars);
683 GtkMenuShell *menu_shell = GTK_MENU_SHELL (menubars->data);
685 _gtk_menu_shell_set_keyboard_mode (menu_shell, TRUE);
686 gtk_menu_shell_select_first (menu_shell, FALSE);
688 g_list_free (menubars);
701 add_to_window (GtkWindow *window,
704 GList *menubars = get_menu_bars (window);
708 g_signal_connect (window,
710 G_CALLBACK (window_key_press_handler),
714 set_menu_bars (window, g_list_prepend (menubars, menubar));
718 remove_from_window (GtkWindow *window,
721 GList *menubars = get_menu_bars (window);
723 menubars = g_list_remove (menubars, menubar);
727 g_signal_handlers_disconnect_by_func (window,
728 window_key_press_handler,
732 set_menu_bars (window, menubars);
736 gtk_menu_bar_hierarchy_changed (GtkWidget *widget,
737 GtkWidget *old_toplevel)
742 menubar = GTK_MENU_BAR (widget);
744 toplevel = gtk_widget_get_toplevel (widget);
747 remove_from_window (GTK_WINDOW (old_toplevel), menubar);
749 if (gtk_widget_is_toplevel (toplevel))
750 add_to_window (GTK_WINDOW (toplevel), menubar);
754 * _gtk_menu_bar_cycle_focus:
755 * @menubar: a #GtkMenuBar
756 * @dir: direction in which to cycle the focus
758 * Move the focus between menubars in the toplevel.
761 _gtk_menu_bar_cycle_focus (GtkMenuBar *menubar,
762 GtkDirectionType dir)
764 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menubar));
765 GtkMenuItem *to_activate = NULL;
767 if (gtk_widget_is_toplevel (toplevel))
769 GList *tmp_menubars = get_viewable_menu_bars (GTK_WINDOW (toplevel));
773 menubars = _gtk_container_focus_sort (GTK_CONTAINER (toplevel), tmp_menubars,
774 dir, GTK_WIDGET (menubar));
775 g_list_free (tmp_menubars);
779 current = g_list_find (menubars, menubar);
781 if (current && current->next)
783 GtkMenuShell *new_menushell = GTK_MENU_SHELL (current->next->data);
784 if (new_menushell->priv->children)
785 to_activate = new_menushell->priv->children->data;
789 g_list_free (menubars);
792 gtk_menu_shell_cancel (GTK_MENU_SHELL (menubar));
795 g_signal_emit_by_name (to_activate, "activate_item");
799 get_shadow_type (GtkMenuBar *menubar)
801 GtkShadowType shadow_type = GTK_SHADOW_OUT;
803 gtk_widget_style_get (GTK_WIDGET (menubar),
804 "shadow-type", &shadow_type,
811 gtk_menu_bar_get_popup_delay (GtkMenuShell *menu_shell)
815 g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu_shell)),
816 "gtk-menu-bar-popup-delay", &popup_delay,
823 gtk_menu_bar_move_current (GtkMenuShell *menu_shell,
824 GtkMenuDirectionType direction)
826 GtkMenuBar *menubar = GTK_MENU_BAR (menu_shell);
827 GtkTextDirection text_dir;
828 GtkPackDirection pack_dir;
830 text_dir = gtk_widget_get_direction (GTK_WIDGET (menubar));
831 pack_dir = gtk_menu_bar_get_pack_direction (menubar);
833 if (pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL)
835 if ((text_dir == GTK_TEXT_DIR_RTL) == (pack_dir == GTK_PACK_DIRECTION_LTR))
839 case GTK_MENU_DIR_PREV:
840 direction = GTK_MENU_DIR_NEXT;
842 case GTK_MENU_DIR_NEXT:
843 direction = GTK_MENU_DIR_PREV;
853 case GTK_MENU_DIR_PARENT:
854 if ((text_dir == GTK_TEXT_DIR_LTR) == (pack_dir == GTK_PACK_DIRECTION_TTB))
855 direction = GTK_MENU_DIR_PREV;
857 direction = GTK_MENU_DIR_NEXT;
859 case GTK_MENU_DIR_CHILD:
860 if ((text_dir == GTK_TEXT_DIR_LTR) == (pack_dir == GTK_PACK_DIRECTION_TTB))
861 direction = GTK_MENU_DIR_NEXT;
863 direction = GTK_MENU_DIR_PREV;
865 case GTK_MENU_DIR_PREV:
866 if (text_dir == GTK_TEXT_DIR_RTL)
867 direction = GTK_MENU_DIR_CHILD;
869 direction = GTK_MENU_DIR_PARENT;
871 case GTK_MENU_DIR_NEXT:
872 if (text_dir == GTK_TEXT_DIR_RTL)
873 direction = GTK_MENU_DIR_PARENT;
875 direction = GTK_MENU_DIR_CHILD;
881 GTK_MENU_SHELL_CLASS (gtk_menu_bar_parent_class)->move_current (menu_shell, direction);
885 * gtk_menu_bar_get_pack_direction:
886 * @menubar: a #GtkMenuBar
888 * Retrieves the current pack direction of the menubar.
889 * See gtk_menu_bar_set_pack_direction().
891 * Return value: the pack direction
896 gtk_menu_bar_get_pack_direction (GtkMenuBar *menubar)
898 g_return_val_if_fail (GTK_IS_MENU_BAR (menubar),
899 GTK_PACK_DIRECTION_LTR);
901 return menubar->priv->pack_direction;
905 * gtk_menu_bar_set_pack_direction:
906 * @menubar: a #GtkMenuBar
907 * @pack_dir: a new #GtkPackDirection
909 * Sets how items should be packed inside a menubar.
914 gtk_menu_bar_set_pack_direction (GtkMenuBar *menubar,
915 GtkPackDirection pack_dir)
917 GtkMenuBarPrivate *priv;
920 g_return_if_fail (GTK_IS_MENU_BAR (menubar));
922 priv = menubar->priv;
924 if (priv->pack_direction != pack_dir)
926 priv->pack_direction = pack_dir;
928 gtk_widget_queue_resize (GTK_WIDGET (menubar));
930 for (l = GTK_MENU_SHELL (menubar)->priv->children; l; l = l->next)
931 gtk_widget_queue_resize (GTK_WIDGET (l->data));
933 g_object_notify (G_OBJECT (menubar), "pack-direction");
938 * gtk_menu_bar_get_child_pack_direction:
939 * @menubar: a #GtkMenuBar
941 * Retrieves the current child pack direction of the menubar.
942 * See gtk_menu_bar_set_child_pack_direction().
944 * Return value: the child pack direction
949 gtk_menu_bar_get_child_pack_direction (GtkMenuBar *menubar)
951 g_return_val_if_fail (GTK_IS_MENU_BAR (menubar),
952 GTK_PACK_DIRECTION_LTR);
954 return menubar->priv->child_pack_direction;
958 * gtk_menu_bar_set_child_pack_direction:
959 * @menubar: a #GtkMenuBar
960 * @child_pack_dir: a new #GtkPackDirection
962 * Sets how widgets should be packed inside the children of a menubar.
967 gtk_menu_bar_set_child_pack_direction (GtkMenuBar *menubar,
968 GtkPackDirection child_pack_dir)
970 GtkMenuBarPrivate *priv;
973 g_return_if_fail (GTK_IS_MENU_BAR (menubar));
975 priv = menubar->priv;
977 if (priv->child_pack_direction != child_pack_dir)
979 priv->child_pack_direction = child_pack_dir;
981 gtk_widget_queue_resize (GTK_WIDGET (menubar));
983 for (l = GTK_MENU_SHELL (menubar)->priv->children; l; l = l->next)
984 gtk_widget_queue_resize (GTK_WIDGET (l->data));
986 g_object_notify (G_OBJECT (menubar), "child-pack-direction");