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/.
29 #include "gtkmenubar.h"
31 #include "gdk/gdkkeysyms.h"
32 #include "gtkbindings.h"
34 #include "gtkmarshalers.h"
35 #include "gtkmenuitem.h"
36 #include "gtkmenuprivate.h"
37 #include "gtksettings.h"
38 #include "gtksizerequest.h"
39 #include "gtkwindow.h"
42 #include "gtkprivate.h"
44 #define BORDER_SPACING 0
45 #define DEFAULT_IPADDING 1
51 PROP_CHILD_PACK_DIRECTION
54 struct _GtkMenuBarPrivate
56 GtkPackDirection pack_direction;
57 GtkPackDirection child_pack_direction;
61 static void gtk_menu_bar_set_property (GObject *object,
65 static void gtk_menu_bar_get_property (GObject *object,
69 static void gtk_menu_bar_size_request (GtkWidget *widget,
70 GtkRequisition *requisition);
71 static void gtk_menu_bar_get_preferred_width (GtkWidget *widget,
74 static void gtk_menu_bar_get_preferred_height (GtkWidget *widget,
77 static void gtk_menu_bar_size_allocate (GtkWidget *widget,
78 GtkAllocation *allocation);
79 static gint gtk_menu_bar_draw (GtkWidget *widget,
81 static void gtk_menu_bar_hierarchy_changed (GtkWidget *widget,
82 GtkWidget *old_toplevel);
83 static gint gtk_menu_bar_get_popup_delay (GtkMenuShell *menu_shell);
84 static void gtk_menu_bar_move_current (GtkMenuShell *menu_shell,
85 GtkMenuDirectionType direction);
87 static GtkShadowType get_shadow_type (GtkMenuBar *menubar);
89 G_DEFINE_TYPE (GtkMenuBar, gtk_menu_bar, GTK_TYPE_MENU_SHELL)
92 gtk_menu_bar_class_init (GtkMenuBarClass *class)
94 GObjectClass *gobject_class;
95 GtkWidgetClass *widget_class;
96 GtkMenuShellClass *menu_shell_class;
98 GtkBindingSet *binding_set;
100 gobject_class = (GObjectClass*) class;
101 widget_class = (GtkWidgetClass*) class;
102 menu_shell_class = (GtkMenuShellClass*) class;
104 gobject_class->get_property = gtk_menu_bar_get_property;
105 gobject_class->set_property = gtk_menu_bar_set_property;
107 widget_class->get_preferred_width = gtk_menu_bar_get_preferred_width;
108 widget_class->get_preferred_height = gtk_menu_bar_get_preferred_height;
109 widget_class->size_allocate = gtk_menu_bar_size_allocate;
110 widget_class->draw = gtk_menu_bar_draw;
111 widget_class->hierarchy_changed = gtk_menu_bar_hierarchy_changed;
113 menu_shell_class->submenu_placement = GTK_TOP_BOTTOM;
114 menu_shell_class->get_popup_delay = gtk_menu_bar_get_popup_delay;
115 menu_shell_class->move_current = gtk_menu_bar_move_current;
117 binding_set = gtk_binding_set_by_class (class);
118 gtk_binding_entry_add_signal (binding_set,
121 GTK_TYPE_MENU_DIRECTION_TYPE,
123 gtk_binding_entry_add_signal (binding_set,
126 GTK_TYPE_MENU_DIRECTION_TYPE,
128 gtk_binding_entry_add_signal (binding_set,
131 GTK_TYPE_MENU_DIRECTION_TYPE,
133 gtk_binding_entry_add_signal (binding_set,
136 GTK_TYPE_MENU_DIRECTION_TYPE,
138 gtk_binding_entry_add_signal (binding_set,
141 GTK_TYPE_MENU_DIRECTION_TYPE,
142 GTK_MENU_DIR_PARENT);
143 gtk_binding_entry_add_signal (binding_set,
146 GTK_TYPE_MENU_DIRECTION_TYPE,
147 GTK_MENU_DIR_PARENT);
148 gtk_binding_entry_add_signal (binding_set,
151 GTK_TYPE_MENU_DIRECTION_TYPE,
153 gtk_binding_entry_add_signal (binding_set,
156 GTK_TYPE_MENU_DIRECTION_TYPE,
160 * GtkMenuBar:pack-direction:
162 * The pack direction of the menubar. It determines how
163 * menuitems are arranged in the menubar.
167 g_object_class_install_property (gobject_class,
169 g_param_spec_enum ("pack-direction",
170 P_("Pack direction"),
171 P_("The pack direction of the menubar"),
172 GTK_TYPE_PACK_DIRECTION,
173 GTK_PACK_DIRECTION_LTR,
174 GTK_PARAM_READWRITE));
177 * GtkMenuBar:child-pack-direction:
179 * The child pack direction of the menubar. It determines how
180 * the widgets contained in child menuitems are arranged.
184 g_object_class_install_property (gobject_class,
185 PROP_CHILD_PACK_DIRECTION,
186 g_param_spec_enum ("child-pack-direction",
187 P_("Child Pack direction"),
188 P_("The child pack direction of the menubar"),
189 GTK_TYPE_PACK_DIRECTION,
190 GTK_PACK_DIRECTION_LTR,
191 GTK_PARAM_READWRITE));
194 gtk_widget_class_install_style_property (widget_class,
195 g_param_spec_enum ("shadow-type",
197 P_("Style of bevel around the menubar"),
198 GTK_TYPE_SHADOW_TYPE,
200 GTK_PARAM_READABLE));
202 gtk_widget_class_install_style_property (widget_class,
203 g_param_spec_int ("internal-padding",
204 P_("Internal padding"),
205 P_("Amount of border space between the menubar shadow and the menu items"),
209 GTK_PARAM_READABLE));
211 g_type_class_add_private (gobject_class, sizeof (GtkMenuBarPrivate));
215 gtk_menu_bar_init (GtkMenuBar *menu_bar)
217 GtkStyleContext *context;
219 menu_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (menu_bar,
223 context = gtk_widget_get_style_context (GTK_WIDGET (menu_bar));
224 gtk_style_context_add_class (context, GTK_STYLE_CLASS_MENUBAR);
228 gtk_menu_bar_new (void)
230 return g_object_new (GTK_TYPE_MENU_BAR, NULL);
234 gtk_menu_bar_set_property (GObject *object,
239 GtkMenuBar *menubar = GTK_MENU_BAR (object);
243 case PROP_PACK_DIRECTION:
244 gtk_menu_bar_set_pack_direction (menubar, g_value_get_enum (value));
246 case PROP_CHILD_PACK_DIRECTION:
247 gtk_menu_bar_set_child_pack_direction (menubar, g_value_get_enum (value));
250 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
256 gtk_menu_bar_get_property (GObject *object,
261 GtkMenuBar *menubar = GTK_MENU_BAR (object);
265 case PROP_PACK_DIRECTION:
266 g_value_set_enum (value, gtk_menu_bar_get_pack_direction (menubar));
268 case PROP_CHILD_PACK_DIRECTION:
269 g_value_set_enum (value, gtk_menu_bar_get_child_pack_direction (menubar));
272 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
278 gtk_menu_bar_size_request (GtkWidget *widget,
279 GtkRequisition *requisition)
281 GtkMenuBar *menu_bar;
282 GtkMenuBarPrivate *priv;
283 GtkMenuShell *menu_shell;
287 GtkRequisition child_requisition;
291 g_return_if_fail (GTK_IS_MENU_BAR (widget));
292 g_return_if_fail (requisition != NULL);
294 requisition->width = 0;
295 requisition->height = 0;
297 if (gtk_widget_get_visible (widget))
299 menu_bar = GTK_MENU_BAR (widget);
300 menu_shell = GTK_MENU_SHELL (widget);
301 priv = menu_bar->priv;
304 children = menu_shell->children;
308 child = children->data;
309 children = children->next;
311 if (gtk_widget_get_visible (child))
315 GTK_MENU_ITEM (child)->show_submenu_indicator = FALSE;
316 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
317 gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
320 if (priv->child_pack_direction == GTK_PACK_DIRECTION_LTR ||
321 priv->child_pack_direction == GTK_PACK_DIRECTION_RTL)
322 child_requisition.width += toggle_size;
324 child_requisition.height += toggle_size;
326 if (priv->pack_direction == GTK_PACK_DIRECTION_LTR ||
327 priv->pack_direction == GTK_PACK_DIRECTION_RTL)
329 requisition->width += child_requisition.width;
330 requisition->height = MAX (requisition->height, child_requisition.height);
334 requisition->width = MAX (requisition->width, child_requisition.width);
335 requisition->height += child_requisition.height;
341 gtk_widget_style_get (widget, "internal-padding", &ipadding, NULL);
343 border_width = gtk_container_get_border_width (GTK_CONTAINER (menu_bar));
344 requisition->width += (border_width +
347 requisition->height += (border_width +
351 if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
353 GtkStyleContext *context;
356 context = gtk_widget_get_style_context (widget);
358 gtk_style_context_get (context, 0,
359 "border-width", &border_width,
362 requisition->width += border_width * 2;
363 requisition->height += border_width * 2;
369 gtk_menu_bar_get_preferred_width (GtkWidget *widget,
373 GtkRequisition requisition;
375 gtk_menu_bar_size_request (widget, &requisition);
377 *minimum = *natural = requisition.width;
381 gtk_menu_bar_get_preferred_height (GtkWidget *widget,
385 GtkRequisition requisition;
387 gtk_menu_bar_size_request (widget, &requisition);
389 *minimum = *natural = requisition.height;
393 gtk_menu_bar_size_allocate (GtkWidget *widget,
394 GtkAllocation *allocation)
396 GtkMenuBar *menu_bar;
397 GtkMenuShell *menu_shell;
398 GtkMenuBarPrivate *priv;
401 GtkAllocation child_allocation;
402 GtkRequisition child_requisition;
404 GtkTextDirection direction;
409 g_return_if_fail (GTK_IS_MENU_BAR (widget));
410 g_return_if_fail (allocation != NULL);
412 menu_bar = GTK_MENU_BAR (widget);
413 menu_shell = GTK_MENU_SHELL (widget);
414 priv = menu_bar->priv;
416 direction = gtk_widget_get_direction (widget);
418 gtk_widget_set_allocation (widget, allocation);
420 if (gtk_widget_get_realized (widget))
421 gdk_window_move_resize (gtk_widget_get_window (widget),
422 allocation->x, allocation->y,
423 allocation->width, allocation->height);
425 gtk_widget_style_get (widget, "internal-padding", &ipadding, NULL);
427 if (menu_shell->children)
429 border_width = gtk_container_get_border_width (GTK_CONTAINER (menu_bar));
430 child_allocation.x = (border_width +
433 child_allocation.y = (border_width +
436 if (get_shadow_type (menu_bar) != GTK_SHADOW_NONE)
438 GtkStyleContext *context;
441 context = gtk_widget_get_style_context (widget);
442 gtk_style_context_get (context, 0,
443 "border-width", &border_width,
446 child_allocation.x += border_width;
447 child_allocation.y += border_width;
450 if (priv->pack_direction == GTK_PACK_DIRECTION_LTR ||
451 priv->pack_direction == GTK_PACK_DIRECTION_RTL)
453 child_allocation.height = MAX (1, (gint)allocation->height - child_allocation.y * 2);
455 offset = child_allocation.x; /* Window edge to menubar start */
456 ltr_x = child_allocation.x;
458 children = menu_shell->children;
463 child = children->data;
464 children = children->next;
466 gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
468 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
470 if (priv->child_pack_direction == GTK_PACK_DIRECTION_LTR ||
471 priv->child_pack_direction == GTK_PACK_DIRECTION_RTL)
472 child_requisition.width += toggle_size;
474 child_requisition.height += toggle_size;
476 /* Support for the right justified help menu */
477 if ((children == NULL) && (GTK_IS_MENU_ITEM(child))
478 && (GTK_MENU_ITEM(child)->right_justify))
480 ltr_x = allocation->width -
481 child_requisition.width - offset;
483 if (gtk_widget_get_visible (child))
485 if ((direction == GTK_TEXT_DIR_LTR) == (priv->pack_direction == GTK_PACK_DIRECTION_LTR))
486 child_allocation.x = ltr_x;
488 child_allocation.x = allocation->width -
489 child_requisition.width - ltr_x;
491 child_allocation.width = child_requisition.width;
493 gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child),
495 gtk_widget_size_allocate (child, &child_allocation);
497 ltr_x += child_allocation.width;
503 child_allocation.width = MAX (1, (gint)allocation->width - child_allocation.x * 2);
505 offset = child_allocation.y; /* Window edge to menubar start */
506 ltr_y = child_allocation.y;
508 children = menu_shell->children;
513 child = children->data;
514 children = children->next;
516 gtk_menu_item_toggle_size_request (GTK_MENU_ITEM (child),
518 gtk_widget_get_preferred_size (child, &child_requisition, NULL);
520 if (priv->child_pack_direction == GTK_PACK_DIRECTION_LTR ||
521 priv->child_pack_direction == GTK_PACK_DIRECTION_RTL)
522 child_requisition.width += toggle_size;
524 child_requisition.height += toggle_size;
526 /* Support for the right justified help menu */
527 if ((children == NULL) && (GTK_IS_MENU_ITEM(child))
528 && (GTK_MENU_ITEM(child)->right_justify))
530 ltr_y = allocation->height -
531 child_requisition.height - offset;
533 if (gtk_widget_get_visible (child))
535 if ((direction == GTK_TEXT_DIR_LTR) ==
536 (priv->pack_direction == GTK_PACK_DIRECTION_TTB))
537 child_allocation.y = ltr_y;
539 child_allocation.y = allocation->height -
540 child_requisition.height - ltr_y;
541 child_allocation.height = child_requisition.height;
543 gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child),
545 gtk_widget_size_allocate (child, &child_allocation);
547 ltr_y += child_allocation.height;
555 gtk_menu_bar_draw (GtkWidget *widget,
558 GtkStyleContext *context;
562 border = gtk_container_get_border_width (GTK_CONTAINER (widget));
563 context = gtk_widget_get_style_context (widget);
565 state = gtk_widget_get_state_flags (widget);
566 gtk_style_context_set_state (context, state);
568 if (get_shadow_type (GTK_MENU_BAR (widget)) != GTK_SHADOW_NONE)
569 gtk_render_background (context, cr,
571 gtk_widget_get_allocated_width (widget) - border * 2,
572 gtk_widget_get_allocated_height (widget) - border * 2);
574 gtk_render_frame (context, cr,
576 gtk_widget_get_allocated_width (widget) - border * 2,
577 gtk_widget_get_allocated_height (widget) - border * 2);
579 GTK_WIDGET_CLASS (gtk_menu_bar_parent_class)->draw (widget, cr);
585 get_menu_bars (GtkWindow *window)
587 return g_object_get_data (G_OBJECT (window), "gtk-menu-bar-list");
591 get_viewable_menu_bars (GtkWindow *window)
594 GList *viewable_menu_bars = NULL;
596 for (menu_bars = get_menu_bars (window);
598 menu_bars = menu_bars->next)
600 GtkWidget *widget = menu_bars->data;
601 gboolean viewable = TRUE;
605 if (!gtk_widget_get_mapped (widget))
608 widget = gtk_widget_get_parent (widget);
612 viewable_menu_bars = g_list_prepend (viewable_menu_bars, menu_bars->data);
615 return g_list_reverse (viewable_menu_bars);
619 set_menu_bars (GtkWindow *window,
622 g_object_set_data (G_OBJECT (window), I_("gtk-menu-bar-list"), menubars);
626 window_key_press_handler (GtkWidget *widget,
631 gboolean retval = FALSE;
633 g_object_get (gtk_widget_get_settings (widget),
634 "gtk-menu-bar-accel", &accel,
640 GdkModifierType mods = 0;
642 gtk_accelerator_parse (accel, &keyval, &mods);
645 g_warning ("Failed to parse menu bar accelerator '%s'\n", accel);
647 /* FIXME this is wrong, needs to be in the global accel resolution
648 * thing, to properly consider i18n etc., but that probably requires
649 * AccelGroup changes etc.
651 if (event->keyval == keyval &&
652 ((event->state & gtk_accelerator_get_default_mod_mask ()) ==
653 (mods & gtk_accelerator_get_default_mod_mask ())))
655 GList *tmp_menubars = get_viewable_menu_bars (GTK_WINDOW (widget));
658 menubars = _gtk_container_focus_sort (GTK_CONTAINER (widget), tmp_menubars,
659 GTK_DIR_TAB_FORWARD, NULL);
660 g_list_free (tmp_menubars);
664 GtkMenuShell *menu_shell = GTK_MENU_SHELL (menubars->data);
666 _gtk_menu_shell_set_keyboard_mode (menu_shell, TRUE);
667 _gtk_menu_shell_activate (menu_shell);
668 gtk_menu_shell_select_first (menu_shell, FALSE);
670 g_list_free (menubars);
683 add_to_window (GtkWindow *window,
686 GList *menubars = get_menu_bars (window);
690 g_signal_connect (window,
692 G_CALLBACK (window_key_press_handler),
696 set_menu_bars (window, g_list_prepend (menubars, menubar));
700 remove_from_window (GtkWindow *window,
703 GList *menubars = get_menu_bars (window);
705 menubars = g_list_remove (menubars, menubar);
709 g_signal_handlers_disconnect_by_func (window,
710 window_key_press_handler,
714 set_menu_bars (window, menubars);
718 gtk_menu_bar_hierarchy_changed (GtkWidget *widget,
719 GtkWidget *old_toplevel)
724 menubar = GTK_MENU_BAR (widget);
726 toplevel = gtk_widget_get_toplevel (widget);
729 remove_from_window (GTK_WINDOW (old_toplevel), menubar);
731 if (gtk_widget_is_toplevel (toplevel))
732 add_to_window (GTK_WINDOW (toplevel), menubar);
736 * _gtk_menu_bar_cycle_focus:
737 * @menubar: a #GtkMenuBar
738 * @dir: direction in which to cycle the focus
740 * Move the focus between menubars in the toplevel.
743 _gtk_menu_bar_cycle_focus (GtkMenuBar *menubar,
744 GtkDirectionType dir)
746 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menubar));
747 GtkMenuItem *to_activate = NULL;
749 if (gtk_widget_is_toplevel (toplevel))
751 GList *tmp_menubars = get_viewable_menu_bars (GTK_WINDOW (toplevel));
755 menubars = _gtk_container_focus_sort (GTK_CONTAINER (toplevel), tmp_menubars,
756 dir, GTK_WIDGET (menubar));
757 g_list_free (tmp_menubars);
761 current = g_list_find (menubars, menubar);
763 if (current && current->next)
765 GtkMenuShell *new_menushell = GTK_MENU_SHELL (current->next->data);
766 if (new_menushell->children)
767 to_activate = new_menushell->children->data;
771 g_list_free (menubars);
774 gtk_menu_shell_cancel (GTK_MENU_SHELL (menubar));
777 g_signal_emit_by_name (to_activate, "activate_item");
781 get_shadow_type (GtkMenuBar *menubar)
783 GtkShadowType shadow_type = GTK_SHADOW_OUT;
785 gtk_widget_style_get (GTK_WIDGET (menubar),
786 "shadow-type", &shadow_type,
793 gtk_menu_bar_get_popup_delay (GtkMenuShell *menu_shell)
797 g_object_get (gtk_widget_get_settings (GTK_WIDGET (menu_shell)),
798 "gtk-menu-bar-popup-delay", &popup_delay,
805 gtk_menu_bar_move_current (GtkMenuShell *menu_shell,
806 GtkMenuDirectionType direction)
808 GtkMenuBar *menubar = GTK_MENU_BAR (menu_shell);
809 GtkTextDirection text_dir;
810 GtkPackDirection pack_dir;
812 text_dir = gtk_widget_get_direction (GTK_WIDGET (menubar));
813 pack_dir = gtk_menu_bar_get_pack_direction (menubar);
815 if (pack_dir == GTK_PACK_DIRECTION_LTR || pack_dir == GTK_PACK_DIRECTION_RTL)
817 if ((text_dir == GTK_TEXT_DIR_RTL) == (pack_dir == GTK_PACK_DIRECTION_LTR))
821 case GTK_MENU_DIR_PREV:
822 direction = GTK_MENU_DIR_NEXT;
824 case GTK_MENU_DIR_NEXT:
825 direction = GTK_MENU_DIR_PREV;
835 case GTK_MENU_DIR_PARENT:
836 if ((text_dir == GTK_TEXT_DIR_LTR) == (pack_dir == GTK_PACK_DIRECTION_TTB))
837 direction = GTK_MENU_DIR_PREV;
839 direction = GTK_MENU_DIR_NEXT;
841 case GTK_MENU_DIR_CHILD:
842 if ((text_dir == GTK_TEXT_DIR_LTR) == (pack_dir == GTK_PACK_DIRECTION_TTB))
843 direction = GTK_MENU_DIR_NEXT;
845 direction = GTK_MENU_DIR_PREV;
847 case GTK_MENU_DIR_PREV:
848 if (text_dir == GTK_TEXT_DIR_RTL)
849 direction = GTK_MENU_DIR_CHILD;
851 direction = GTK_MENU_DIR_PARENT;
853 case GTK_MENU_DIR_NEXT:
854 if (text_dir == GTK_TEXT_DIR_RTL)
855 direction = GTK_MENU_DIR_PARENT;
857 direction = GTK_MENU_DIR_CHILD;
863 GTK_MENU_SHELL_CLASS (gtk_menu_bar_parent_class)->move_current (menu_shell, direction);
867 * gtk_menu_bar_get_pack_direction:
868 * @menubar: a #GtkMenuBar
870 * Retrieves the current pack direction of the menubar.
871 * See gtk_menu_bar_set_pack_direction().
873 * Return value: the pack direction
878 gtk_menu_bar_get_pack_direction (GtkMenuBar *menubar)
880 g_return_val_if_fail (GTK_IS_MENU_BAR (menubar),
881 GTK_PACK_DIRECTION_LTR);
883 return menubar->priv->pack_direction;
887 * gtk_menu_bar_set_pack_direction:
888 * @menubar: a #GtkMenuBar
889 * @pack_dir: a new #GtkPackDirection
891 * Sets how items should be packed inside a menubar.
896 gtk_menu_bar_set_pack_direction (GtkMenuBar *menubar,
897 GtkPackDirection pack_dir)
899 GtkMenuBarPrivate *priv;
902 g_return_if_fail (GTK_IS_MENU_BAR (menubar));
904 priv = menubar->priv;
906 if (priv->pack_direction != pack_dir)
908 priv->pack_direction = pack_dir;
910 gtk_widget_queue_resize (GTK_WIDGET (menubar));
912 for (l = GTK_MENU_SHELL (menubar)->children; l; l = l->next)
913 gtk_widget_queue_resize (GTK_WIDGET (l->data));
915 g_object_notify (G_OBJECT (menubar), "pack-direction");
920 * gtk_menu_bar_get_child_pack_direction:
921 * @menubar: a #GtkMenuBar
923 * Retrieves the current child pack direction of the menubar.
924 * See gtk_menu_bar_set_child_pack_direction().
926 * Return value: the child pack direction
931 gtk_menu_bar_get_child_pack_direction (GtkMenuBar *menubar)
933 g_return_val_if_fail (GTK_IS_MENU_BAR (menubar),
934 GTK_PACK_DIRECTION_LTR);
936 return menubar->priv->child_pack_direction;
940 * gtk_menu_bar_set_child_pack_direction:
941 * @menubar: a #GtkMenuBar
942 * @child_pack_dir: a new #GtkPackDirection
944 * Sets how widgets should be packed inside the children of a menubar.
949 gtk_menu_bar_set_child_pack_direction (GtkMenuBar *menubar,
950 GtkPackDirection child_pack_dir)
952 GtkMenuBarPrivate *priv;
955 g_return_if_fail (GTK_IS_MENU_BAR (menubar));
957 priv = menubar->priv;
959 if (priv->child_pack_direction != child_pack_dir)
961 priv->child_pack_direction = child_pack_dir;
963 gtk_widget_queue_resize (GTK_WIDGET (menubar));
965 for (l = GTK_MENU_SHELL (menubar)->children; l; l = l->next)
966 gtk_widget_queue_resize (GTK_WIDGET (l->data));
968 g_object_notify (G_OBJECT (menubar), "child-pack-direction");