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_size_request (GtkWidget *widget,
81 GtkRequisition *requisition);
82 static void gtk_menu_bar_get_preferred_width (GtkWidget *widget,
85 static void gtk_menu_bar_get_preferred_height (GtkWidget *widget,
88 static void gtk_menu_bar_size_allocate (GtkWidget *widget,
89 GtkAllocation *allocation);
90 static gint gtk_menu_bar_draw (GtkWidget *widget,
92 static void gtk_menu_bar_hierarchy_changed (GtkWidget *widget,
93 GtkWidget *old_toplevel);
94 static gint gtk_menu_bar_get_popup_delay (GtkMenuShell *menu_shell);
95 static void gtk_menu_bar_move_current (GtkMenuShell *menu_shell,
96 GtkMenuDirectionType direction);
98 static GtkShadowType get_shadow_type (GtkMenuBar *menubar);
100 G_DEFINE_TYPE (GtkMenuBar, gtk_menu_bar, GTK_TYPE_MENU_SHELL)
103 gtk_menu_bar_class_init (GtkMenuBarClass *class)
105 GObjectClass *gobject_class;
106 GtkWidgetClass *widget_class;
107 GtkMenuShellClass *menu_shell_class;
109 GtkBindingSet *binding_set;
111 gobject_class = (GObjectClass*) class;
112 widget_class = (GtkWidgetClass*) class;
113 menu_shell_class = (GtkMenuShellClass*) class;
115 gobject_class->get_property = gtk_menu_bar_get_property;
116 gobject_class->set_property = gtk_menu_bar_set_property;
118 widget_class->get_preferred_width = gtk_menu_bar_get_preferred_width;
119 widget_class->get_preferred_height = gtk_menu_bar_get_preferred_height;
120 widget_class->size_allocate = gtk_menu_bar_size_allocate;
121 widget_class->draw = gtk_menu_bar_draw;
122 widget_class->hierarchy_changed = gtk_menu_bar_hierarchy_changed;
124 menu_shell_class->submenu_placement = GTK_TOP_BOTTOM;
125 menu_shell_class->get_popup_delay = gtk_menu_bar_get_popup_delay;
126 menu_shell_class->move_current = gtk_menu_bar_move_current;
128 binding_set = gtk_binding_set_by_class (class);
129 gtk_binding_entry_add_signal (binding_set,
132 GTK_TYPE_MENU_DIRECTION_TYPE,
134 gtk_binding_entry_add_signal (binding_set,
137 GTK_TYPE_MENU_DIRECTION_TYPE,
139 gtk_binding_entry_add_signal (binding_set,
142 GTK_TYPE_MENU_DIRECTION_TYPE,
144 gtk_binding_entry_add_signal (binding_set,
147 GTK_TYPE_MENU_DIRECTION_TYPE,
149 gtk_binding_entry_add_signal (binding_set,
152 GTK_TYPE_MENU_DIRECTION_TYPE,
153 GTK_MENU_DIR_PARENT);
154 gtk_binding_entry_add_signal (binding_set,
157 GTK_TYPE_MENU_DIRECTION_TYPE,
158 GTK_MENU_DIR_PARENT);
159 gtk_binding_entry_add_signal (binding_set,
162 GTK_TYPE_MENU_DIRECTION_TYPE,
164 gtk_binding_entry_add_signal (binding_set,
167 GTK_TYPE_MENU_DIRECTION_TYPE,
171 * GtkMenuBar:pack-direction:
173 * The pack direction of the menubar. It determines how
174 * menuitems are arranged in the menubar.
178 g_object_class_install_property (gobject_class,
180 g_param_spec_enum ("pack-direction",
181 P_("Pack direction"),
182 P_("The pack direction of the menubar"),
183 GTK_TYPE_PACK_DIRECTION,
184 GTK_PACK_DIRECTION_LTR,
185 GTK_PARAM_READWRITE));
188 * GtkMenuBar:child-pack-direction:
190 * The child pack direction of the menubar. It determines how
191 * the widgets contained in child menuitems are arranged.
195 g_object_class_install_property (gobject_class,
196 PROP_CHILD_PACK_DIRECTION,
197 g_param_spec_enum ("child-pack-direction",
198 P_("Child Pack direction"),
199 P_("The child pack direction of the menubar"),
200 GTK_TYPE_PACK_DIRECTION,
201 GTK_PACK_DIRECTION_LTR,
202 GTK_PARAM_READWRITE));
205 gtk_widget_class_install_style_property (widget_class,
206 g_param_spec_enum ("shadow-type",
208 P_("Style of bevel around the menubar"),
209 GTK_TYPE_SHADOW_TYPE,
211 GTK_PARAM_READABLE));
213 gtk_widget_class_install_style_property (widget_class,
214 g_param_spec_int ("internal-padding",
215 P_("Internal padding"),
216 P_("Amount of border space between the menubar shadow and the menu items"),
220 GTK_PARAM_READABLE));
222 g_type_class_add_private (gobject_class, sizeof (GtkMenuBarPrivate));
226 gtk_menu_bar_init (GtkMenuBar *menu_bar)
228 GtkStyleContext *context;
230 menu_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (menu_bar,
234 context = gtk_widget_get_style_context (GTK_WIDGET (menu_bar));
235 gtk_style_context_add_class (context, GTK_STYLE_CLASS_MENUBAR);
241 * Creates a new #GtkMenuBar
243 * Returns: the new menu bar, as a #GtkWidget
246 gtk_menu_bar_new (void)
248 return g_object_new (GTK_TYPE_MENU_BAR, NULL);
252 gtk_menu_bar_set_property (GObject *object,
257 GtkMenuBar *menubar = GTK_MENU_BAR (object);
261 case PROP_PACK_DIRECTION:
262 gtk_menu_bar_set_pack_direction (menubar, g_value_get_enum (value));
264 case PROP_CHILD_PACK_DIRECTION:
265 gtk_menu_bar_set_child_pack_direction (menubar, g_value_get_enum (value));
268 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
274 gtk_menu_bar_get_property (GObject *object,
279 GtkMenuBar *menubar = GTK_MENU_BAR (object);
283 case PROP_PACK_DIRECTION:
284 g_value_set_enum (value, gtk_menu_bar_get_pack_direction (menubar));
286 case PROP_CHILD_PACK_DIRECTION:
287 g_value_set_enum (value, gtk_menu_bar_get_child_pack_direction (menubar));
290 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
296 gtk_menu_bar_size_request (GtkWidget *widget,
297 GtkRequisition *requisition)
299 GtkMenuBar *menu_bar;
300 GtkMenuBarPrivate *priv;
301 GtkMenuShell *menu_shell;
305 GtkRequisition child_requisition;
309 g_return_if_fail (GTK_IS_MENU_BAR (widget));
310 g_return_if_fail (requisition != NULL);
312 requisition->width = 0;
313 requisition->height = 0;
315 if (gtk_widget_get_visible (widget))
317 menu_bar = GTK_MENU_BAR (widget);
318 menu_shell = GTK_MENU_SHELL (widget);
319 priv = menu_bar->priv;
322 children = menu_shell->priv->children;
326 child = children->data;
327 children = children->next;
329 if (gtk_widget_get_visible (child))
333 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
334 gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
337 if (priv->child_pack_direction == GTK_PACK_DIRECTION_LTR ||
338 priv->child_pack_direction == GTK_PACK_DIRECTION_RTL)
339 child_requisition.width += toggle_size;
341 child_requisition.height += toggle_size;
343 if (priv->pack_direction == GTK_PACK_DIRECTION_LTR ||
344 priv->pack_direction == GTK_PACK_DIRECTION_RTL)
346 requisition->width += child_requisition.width;
347 requisition->height = MAX (requisition->height, child_requisition.height);
351 requisition->width = MAX (requisition->width, child_requisition.width);
352 requisition->height += child_requisition.height;
358 gtk_widget_style_get (widget, "internal-padding", &ipadding, NULL);
360 border_width = gtk_container_get_border_width (GTK_CONTAINER (menu_bar));
361 requisition->width += (border_width +
364 requisition->height += (border_width +
368 if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
370 GtkStyleContext *context;
373 context = gtk_widget_get_style_context (widget);
375 gtk_style_context_get (context, 0,
376 "border-width", &border,
379 requisition->width += border->left + border->right;
380 requisition->height += border->top + border->bottom;
381 gtk_border_free (border);
387 gtk_menu_bar_get_preferred_width (GtkWidget *widget,
391 GtkRequisition requisition;
393 gtk_menu_bar_size_request (widget, &requisition);
395 *minimum = *natural = requisition.width;
399 gtk_menu_bar_get_preferred_height (GtkWidget *widget,
403 GtkRequisition requisition;
405 gtk_menu_bar_size_request (widget, &requisition);
407 *minimum = *natural = requisition.height;
411 gtk_menu_bar_size_allocate (GtkWidget *widget,
412 GtkAllocation *allocation)
414 GtkMenuBar *menu_bar;
415 GtkMenuShell *menu_shell;
416 GtkMenuBarPrivate *priv;
419 GtkAllocation child_allocation;
420 GtkRequisition child_requisition;
422 GtkTextDirection direction;
427 g_return_if_fail (GTK_IS_MENU_BAR (widget));
428 g_return_if_fail (allocation != NULL);
430 menu_bar = GTK_MENU_BAR (widget);
431 menu_shell = GTK_MENU_SHELL (widget);
432 priv = menu_bar->priv;
434 direction = gtk_widget_get_direction (widget);
436 gtk_widget_set_allocation (widget, allocation);
438 if (gtk_widget_get_realized (widget))
439 gdk_window_move_resize (gtk_widget_get_window (widget),
440 allocation->x, allocation->y,
441 allocation->width, allocation->height);
443 gtk_widget_style_get (widget, "internal-padding", &ipadding, NULL);
445 if (menu_shell->priv->children)
447 border_width = gtk_container_get_border_width (GTK_CONTAINER (menu_bar));
448 child_allocation.x = (border_width +
451 child_allocation.y = (border_width +
454 if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
456 GtkStyleContext *context;
459 context = gtk_widget_get_style_context (widget);
460 gtk_style_context_get (context, 0,
461 "border-width", &border,
464 child_allocation.x += border->left;
465 child_allocation.y += border->top;
467 gtk_border_free (border);
470 if (priv->pack_direction == GTK_PACK_DIRECTION_LTR ||
471 priv->pack_direction == GTK_PACK_DIRECTION_RTL)
473 child_allocation.height = MAX (1, (gint)allocation->height - child_allocation.y * 2);
475 offset = child_allocation.x; /* Window edge to menubar start */
476 ltr_x = child_allocation.x;
478 children = menu_shell->priv->children;
483 child = children->data;
484 children = children->next;
486 gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
488 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
490 if (priv->child_pack_direction == GTK_PACK_DIRECTION_LTR ||
491 priv->child_pack_direction == GTK_PACK_DIRECTION_RTL)
492 child_requisition.width += toggle_size;
494 child_requisition.height += toggle_size;
496 /* Support for the right justified help menu */
497 if (children == NULL &&
498 GTK_IS_MENU_ITEM (child) &&
499 GTK_MENU_ITEM (child)->priv->right_justify)
501 ltr_x = allocation->width -
502 child_requisition.width - offset;
504 if (gtk_widget_get_visible (child))
506 if ((direction == GTK_TEXT_DIR_LTR) == (priv->pack_direction == GTK_PACK_DIRECTION_LTR))
507 child_allocation.x = ltr_x;
509 child_allocation.x = allocation->width -
510 child_requisition.width - ltr_x;
512 child_allocation.width = child_requisition.width;
514 gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child),
516 gtk_widget_size_allocate (child, &child_allocation);
518 ltr_x += child_allocation.width;
524 child_allocation.width = MAX (1, (gint)allocation->width - child_allocation.x * 2);
526 offset = child_allocation.y; /* Window edge to menubar start */
527 ltr_y = child_allocation.y;
529 children = menu_shell->priv->children;
534 child = children->data;
535 children = children->next;
537 gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
539 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
541 if (priv->child_pack_direction == GTK_PACK_DIRECTION_LTR ||
542 priv->child_pack_direction == GTK_PACK_DIRECTION_RTL)
543 child_requisition.width += toggle_size;
545 child_requisition.height += toggle_size;
547 /* Support for the right justified help menu */
548 if (children == NULL &&
549 GTK_IS_MENU_ITEM (child) &&
550 GTK_MENU_ITEM (child)->priv->right_justify)
552 ltr_y = allocation->height -
553 child_requisition.height - offset;
555 if (gtk_widget_get_visible (child))
557 if ((direction == GTK_TEXT_DIR_LTR) ==
558 (priv->pack_direction == GTK_PACK_DIRECTION_TTB))
559 child_allocation.y = ltr_y;
561 child_allocation.y = allocation->height -
562 child_requisition.height - ltr_y;
563 child_allocation.height = child_requisition.height;
565 gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child),
567 gtk_widget_size_allocate (child, &child_allocation);
569 ltr_y += child_allocation.height;
577 gtk_menu_bar_draw (GtkWidget *widget,
580 GtkStyleContext *context;
584 border = gtk_container_get_border_width (GTK_CONTAINER (widget));
585 context = gtk_widget_get_style_context (widget);
587 state = gtk_widget_get_state_flags (widget);
588 gtk_style_context_set_state (context, state);
590 if (get_shadow_type (GTK_MENU_BAR (widget)) != GTK_SHADOW_NONE)
591 gtk_render_background (context, cr,
593 gtk_widget_get_allocated_width (widget) - border * 2,
594 gtk_widget_get_allocated_height (widget) - border * 2);
596 gtk_render_frame (context, cr,
598 gtk_widget_get_allocated_width (widget) - border * 2,
599 gtk_widget_get_allocated_height (widget) - border * 2);
601 GTK_WIDGET_CLASS (gtk_menu_bar_parent_class)->draw (widget, cr);
607 get_menu_bars (GtkWindow *window)
609 return g_object_get_data (G_OBJECT (window), "gtk-menu-bar-list");
613 get_viewable_menu_bars (GtkWindow *window)
616 GList *viewable_menu_bars = NULL;
618 for (menu_bars = get_menu_bars (window);
620 menu_bars = menu_bars->next)
622 GtkWidget *widget = menu_bars->data;
623 gboolean viewable = TRUE;
627 if (!gtk_widget_get_mapped (widget))
630 widget = gtk_widget_get_parent (widget);
634 viewable_menu_bars = g_list_prepend (viewable_menu_bars, menu_bars->data);
637 return g_list_reverse (viewable_menu_bars);
641 set_menu_bars (GtkWindow *window,
644 g_object_set_data (G_OBJECT (window), I_("gtk-menu-bar-list"), menubars);
648 window_key_press_handler (GtkWidget *widget,
653 gboolean retval = FALSE;
655 g_object_get (gtk_widget_get_settings (widget),
656 "gtk-menu-bar-accel", &accel,
662 GdkModifierType mods = 0;
664 gtk_accelerator_parse (accel, &keyval, &mods);
667 g_warning ("Failed to parse menu bar accelerator '%s'\n", accel);
669 /* FIXME this is wrong, needs to be in the global accel resolution
670 * thing, to properly consider i18n etc., but that probably requires
671 * AccelGroup changes etc.
673 if (event->keyval == keyval &&
674 ((event->state & gtk_accelerator_get_default_mod_mask ()) ==
675 (mods & gtk_accelerator_get_default_mod_mask ())))
677 GList *tmp_menubars = get_viewable_menu_bars (GTK_WINDOW (widget));
680 menubars = _gtk_container_focus_sort (GTK_CONTAINER (widget), tmp_menubars,
681 GTK_DIR_TAB_FORWARD, NULL);
682 g_list_free (tmp_menubars);
686 GtkMenuShell *menu_shell = GTK_MENU_SHELL (menubars->data);
688 _gtk_menu_shell_set_keyboard_mode (menu_shell, TRUE);
689 _gtk_menu_shell_activate (menu_shell);
690 gtk_menu_shell_select_first (menu_shell, FALSE);
692 g_list_free (menubars);
705 add_to_window (GtkWindow *window,
708 GList *menubars = get_menu_bars (window);
712 g_signal_connect (window,
714 G_CALLBACK (window_key_press_handler),
718 set_menu_bars (window, g_list_prepend (menubars, menubar));
722 remove_from_window (GtkWindow *window,
725 GList *menubars = get_menu_bars (window);
727 menubars = g_list_remove (menubars, menubar);
731 g_signal_handlers_disconnect_by_func (window,
732 window_key_press_handler,
736 set_menu_bars (window, menubars);
740 gtk_menu_bar_hierarchy_changed (GtkWidget *widget,
741 GtkWidget *old_toplevel)
746 menubar = GTK_MENU_BAR (widget);
748 toplevel = gtk_widget_get_toplevel (widget);
751 remove_from_window (GTK_WINDOW (old_toplevel), menubar);
753 if (gtk_widget_is_toplevel (toplevel))
754 add_to_window (GTK_WINDOW (toplevel), menubar);
758 * _gtk_menu_bar_cycle_focus:
759 * @menubar: a #GtkMenuBar
760 * @dir: direction in which to cycle the focus
762 * Move the focus between menubars in the toplevel.
765 _gtk_menu_bar_cycle_focus (GtkMenuBar *menubar,
766 GtkDirectionType dir)
768 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menubar));
769 GtkMenuItem *to_activate = NULL;
771 if (gtk_widget_is_toplevel (toplevel))
773 GList *tmp_menubars = get_viewable_menu_bars (GTK_WINDOW (toplevel));
777 menubars = _gtk_container_focus_sort (GTK_CONTAINER (toplevel), tmp_menubars,
778 dir, GTK_WIDGET (menubar));
779 g_list_free (tmp_menubars);
783 current = g_list_find (menubars, menubar);
785 if (current && current->next)
787 GtkMenuShell *new_menushell = GTK_MENU_SHELL (current->next->data);
788 if (new_menushell->priv->children)
789 to_activate = new_menushell->priv->children->data;
793 g_list_free (menubars);
796 gtk_menu_shell_cancel (GTK_MENU_SHELL (menubar));
799 g_signal_emit_by_name (to_activate, "activate_item");
803 get_shadow_type (GtkMenuBar *menubar)
805 GtkShadowType shadow_type = GTK_SHADOW_OUT;
807 gtk_widget_style_get (GTK_WIDGET (menubar),
808 "shadow-type", &shadow_type,
815 gtk_menu_bar_get_popup_delay (GtkMenuShell *menu_shell)
819 g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu_shell)),
820 "gtk-menu-bar-popup-delay", &popup_delay,
827 gtk_menu_bar_move_current (GtkMenuShell *menu_shell,
828 GtkMenuDirectionType direction)
830 GtkMenuBar *menubar = GTK_MENU_BAR (menu_shell);
831 GtkTextDirection text_dir;
832 GtkPackDirection pack_dir;
834 text_dir = gtk_widget_get_direction (GTK_WIDGET (menubar));
835 pack_dir = gtk_menu_bar_get_pack_direction (menubar);
837 if (pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL)
839 if ((text_dir == GTK_TEXT_DIR_RTL) == (pack_dir == GTK_PACK_DIRECTION_LTR))
843 case GTK_MENU_DIR_PREV:
844 direction = GTK_MENU_DIR_NEXT;
846 case GTK_MENU_DIR_NEXT:
847 direction = GTK_MENU_DIR_PREV;
857 case GTK_MENU_DIR_PARENT:
858 if ((text_dir == GTK_TEXT_DIR_LTR) == (pack_dir == GTK_PACK_DIRECTION_TTB))
859 direction = GTK_MENU_DIR_PREV;
861 direction = GTK_MENU_DIR_NEXT;
863 case GTK_MENU_DIR_CHILD:
864 if ((text_dir == GTK_TEXT_DIR_LTR) == (pack_dir == GTK_PACK_DIRECTION_TTB))
865 direction = GTK_MENU_DIR_NEXT;
867 direction = GTK_MENU_DIR_PREV;
869 case GTK_MENU_DIR_PREV:
870 if (text_dir == GTK_TEXT_DIR_RTL)
871 direction = GTK_MENU_DIR_CHILD;
873 direction = GTK_MENU_DIR_PARENT;
875 case GTK_MENU_DIR_NEXT:
876 if (text_dir == GTK_TEXT_DIR_RTL)
877 direction = GTK_MENU_DIR_PARENT;
879 direction = GTK_MENU_DIR_CHILD;
885 GTK_MENU_SHELL_CLASS (gtk_menu_bar_parent_class)->move_current (menu_shell, direction);
889 * gtk_menu_bar_get_pack_direction:
890 * @menubar: a #GtkMenuBar
892 * Retrieves the current pack direction of the menubar.
893 * See gtk_menu_bar_set_pack_direction().
895 * Return value: the pack direction
900 gtk_menu_bar_get_pack_direction (GtkMenuBar *menubar)
902 g_return_val_if_fail (GTK_IS_MENU_BAR (menubar),
903 GTK_PACK_DIRECTION_LTR);
905 return menubar->priv->pack_direction;
909 * gtk_menu_bar_set_pack_direction:
910 * @menubar: a #GtkMenuBar
911 * @pack_dir: a new #GtkPackDirection
913 * Sets how items should be packed inside a menubar.
918 gtk_menu_bar_set_pack_direction (GtkMenuBar *menubar,
919 GtkPackDirection pack_dir)
921 GtkMenuBarPrivate *priv;
924 g_return_if_fail (GTK_IS_MENU_BAR (menubar));
926 priv = menubar->priv;
928 if (priv->pack_direction != pack_dir)
930 priv->pack_direction = pack_dir;
932 gtk_widget_queue_resize (GTK_WIDGET (menubar));
934 for (l = GTK_MENU_SHELL (menubar)->priv->children; l; l = l->next)
935 gtk_widget_queue_resize (GTK_WIDGET (l->data));
937 g_object_notify (G_OBJECT (menubar), "pack-direction");
942 * gtk_menu_bar_get_child_pack_direction:
943 * @menubar: a #GtkMenuBar
945 * Retrieves the current child pack direction of the menubar.
946 * See gtk_menu_bar_set_child_pack_direction().
948 * Return value: the child pack direction
953 gtk_menu_bar_get_child_pack_direction (GtkMenuBar *menubar)
955 g_return_val_if_fail (GTK_IS_MENU_BAR (menubar),
956 GTK_PACK_DIRECTION_LTR);
958 return menubar->priv->child_pack_direction;
962 * gtk_menu_bar_set_child_pack_direction:
963 * @menubar: a #GtkMenuBar
964 * @child_pack_dir: a new #GtkPackDirection
966 * Sets how widgets should be packed inside the children of a menubar.
971 gtk_menu_bar_set_child_pack_direction (GtkMenuBar *menubar,
972 GtkPackDirection child_pack_dir)
974 GtkMenuBarPrivate *priv;
977 g_return_if_fail (GTK_IS_MENU_BAR (menubar));
979 priv = menubar->priv;
981 if (priv->child_pack_direction != child_pack_dir)
983 priv->child_pack_direction = child_pack_dir;
985 gtk_widget_queue_resize (GTK_WIDGET (menubar));
987 for (l = GTK_MENU_SHELL (menubar)->priv->children; l; l = l->next)
988 gtk_widget_queue_resize (GTK_WIDGET (l->data));
990 g_object_notify (G_OBJECT (menubar), "child-pack-direction");