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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include "gdk/gdkkeysyms.h"
22 #include "gtkmenuitem.h"
23 #include "gtksignal.h"
26 #define MENU_ITEM_CLASS(w) GTK_MENU_ITEM_CLASS (GTK_OBJECT (w)->klass)
29 typedef struct _GtkMenuAttachData GtkMenuAttachData;
31 struct _GtkMenuAttachData
33 GtkWidget *attach_widget;
34 GtkMenuDetachFunc detacher;
38 static void gtk_menu_class_init (GtkMenuClass *klass);
39 static void gtk_menu_init (GtkMenu *menu);
40 static void gtk_menu_destroy (GtkObject *object);
41 static void gtk_menu_show (GtkWidget *widget);
42 static void gtk_menu_map (GtkWidget *widget);
43 static void gtk_menu_unmap (GtkWidget *widget);
44 static void gtk_menu_realize (GtkWidget *widget);
45 static void gtk_menu_size_request (GtkWidget *widget,
46 GtkRequisition *requisition);
47 static void gtk_menu_size_allocate (GtkWidget *widget,
48 GtkAllocation *allocation);
49 static void gtk_menu_paint (GtkWidget *widget);
50 static void gtk_menu_draw (GtkWidget *widget,
52 static gint gtk_menu_expose (GtkWidget *widget,
53 GdkEventExpose *event);
54 static gint gtk_menu_configure (GtkWidget *widget,
55 GdkEventConfigure *event);
56 static gint gtk_menu_key_press (GtkWidget *widget,
58 static gint gtk_menu_need_resize (GtkContainer *container);
59 static void gtk_menu_deactivate (GtkMenuShell *menu_shell);
60 static void gtk_menu_show_all (GtkWidget *widget);
61 static void gtk_menu_hide_all (GtkWidget *widget);
63 static GtkMenuShellClass *parent_class = NULL;
64 static const gchar *attach_data_key = "gtk-menu-attach-data";
70 static guint menu_type = 0;
74 GtkTypeInfo menu_info =
78 sizeof (GtkMenuClass),
79 (GtkClassInitFunc) gtk_menu_class_init,
80 (GtkObjectInitFunc) gtk_menu_init,
85 menu_type = gtk_type_unique (gtk_menu_shell_get_type (), &menu_info);
92 gtk_menu_class_init (GtkMenuClass *class)
94 GtkObjectClass *object_class;
95 GtkWidgetClass *widget_class;
96 GtkContainerClass *container_class;
97 GtkMenuShellClass *menu_shell_class;
99 object_class = (GtkObjectClass*) class;
100 widget_class = (GtkWidgetClass*) class;
101 container_class = (GtkContainerClass*) class;
102 menu_shell_class = (GtkMenuShellClass*) class;
103 parent_class = gtk_type_class (gtk_menu_shell_get_type ());
105 object_class->destroy = gtk_menu_destroy;
107 widget_class->show = gtk_menu_show;
108 widget_class->map = gtk_menu_map;
109 widget_class->unmap = gtk_menu_unmap;
110 widget_class->realize = gtk_menu_realize;
111 widget_class->draw = gtk_menu_draw;
112 widget_class->size_request = gtk_menu_size_request;
113 widget_class->size_allocate = gtk_menu_size_allocate;
114 widget_class->expose_event = gtk_menu_expose;
115 widget_class->configure_event = gtk_menu_configure;
116 widget_class->key_press_event = gtk_menu_key_press;
117 widget_class->show_all = gtk_menu_show_all;
118 widget_class->hide_all = gtk_menu_hide_all;
120 container_class->need_resize = gtk_menu_need_resize;
122 menu_shell_class->submenu_placement = GTK_LEFT_RIGHT;
123 menu_shell_class->deactivate = gtk_menu_deactivate;
127 gtk_menu_init (GtkMenu *menu)
129 GTK_WIDGET_SET_FLAGS (menu, GTK_TOPLEVEL);
131 menu->parent_menu_item = NULL;
132 menu->old_active_menu_item = NULL;
133 menu->accelerator_table = NULL;
134 menu->position_func = NULL;
135 menu->position_func_data = NULL;
137 GTK_MENU_SHELL (menu)->menu_flag = TRUE;
141 gtk_menu_destroy (GtkObject *object)
143 GtkMenuAttachData *data;
145 g_return_if_fail (object != NULL);
146 g_return_if_fail (GTK_IS_MENU (object));
148 gtk_widget_ref (GTK_WIDGET (object));
150 data = gtk_object_get_data (object, attach_data_key);
152 gtk_menu_detach (GTK_MENU (object));
154 gtk_menu_set_accelerator_table (GTK_MENU (object), NULL);
156 if (GTK_OBJECT_CLASS (parent_class)->destroy)
157 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
159 gtk_widget_unref (GTK_WIDGET (object));
164 gtk_menu_attach_to_widget (GtkMenu *menu,
165 GtkWidget *attach_widget,
166 GtkMenuDetachFunc detacher)
168 GtkMenuAttachData *data;
170 g_return_if_fail (menu != NULL);
171 g_return_if_fail (GTK_IS_MENU (menu));
172 g_return_if_fail (attach_widget != NULL);
173 g_return_if_fail (GTK_IS_WIDGET (attach_widget));
174 g_return_if_fail (detacher != NULL);
176 /* keep this function in sync with gtk_widget_set_parent()
179 data = gtk_object_get_data (GTK_OBJECT (menu), attach_data_key);
182 g_warning ("gtk_menu_attach_to_widget(): menu already attached to %s",
183 gtk_type_name (GTK_OBJECT_TYPE (data->attach_widget)));
187 gtk_widget_ref (GTK_WIDGET (menu));
188 gtk_object_sink (GTK_OBJECT (menu));
190 data = g_new (GtkMenuAttachData, 1);
191 data->attach_widget = attach_widget;
192 data->detacher = detacher;
193 gtk_object_set_data (GTK_OBJECT (menu), attach_data_key, data);
195 if (GTK_WIDGET_STATE (menu) != GTK_STATE_NORMAL)
196 gtk_widget_set_state (GTK_WIDGET (menu), GTK_STATE_NORMAL);
198 /* we don't need to set the style here, since
199 * we are a toplevel widget.
204 gtk_menu_get_attach_widget (GtkMenu *menu)
206 GtkMenuAttachData *data;
208 g_return_val_if_fail (menu != NULL, NULL);
209 g_return_val_if_fail (GTK_IS_MENU (menu), NULL);
211 data = gtk_object_get_data (GTK_OBJECT (menu), attach_data_key);
213 return data->attach_widget;
218 gtk_menu_detach (GtkMenu *menu)
220 GtkMenuAttachData *data;
222 g_return_if_fail (menu != NULL);
223 g_return_if_fail (GTK_IS_MENU (menu));
225 /* keep this function in sync with gtk_widget_unparent()
227 data = gtk_object_get_data (GTK_OBJECT (menu), attach_data_key);
230 g_warning ("gtk_menu_detach(): menu is not attached");
233 gtk_object_remove_data (GTK_OBJECT (menu), attach_data_key);
235 data->detacher (data->attach_widget, menu);
237 if (GTK_WIDGET_REALIZED (menu))
238 gtk_widget_unrealize (GTK_WIDGET (menu));
242 gtk_widget_unref (GTK_WIDGET (menu));
248 return GTK_WIDGET (gtk_type_new (gtk_menu_get_type ()));
252 gtk_menu_append (GtkMenu *menu,
255 gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
259 gtk_menu_prepend (GtkMenu *menu,
262 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), child);
266 gtk_menu_insert (GtkMenu *menu,
270 gtk_menu_shell_insert (GTK_MENU_SHELL (menu), child, position);
274 gtk_menu_popup (GtkMenu *menu,
275 GtkWidget *parent_menu_shell,
276 GtkWidget *parent_menu_item,
277 GtkMenuPositionFunc func,
280 guint32 activate_time)
282 GtkWidget *xgrab_shell;
285 g_return_if_fail (menu != NULL);
286 g_return_if_fail (GTK_IS_MENU (menu));
288 GTK_MENU_SHELL (menu)->parent_menu_shell = parent_menu_shell;
289 GTK_MENU_SHELL (menu)->active = TRUE;
290 GTK_MENU_SHELL (menu)->button = button;
292 menu->parent_menu_item = parent_menu_item;
293 menu->position_func = func;
294 menu->position_func_data = data;
295 GTK_MENU_SHELL (menu)->activate_time = activate_time;
297 gtk_widget_show (GTK_WIDGET (menu));
299 /* Find the last viewable ancestor, and make an X grab on it
301 parent = GTK_WIDGET (menu);
305 gboolean viewable = TRUE;
306 GtkWidget *tmp = parent;
310 if (!GTK_WIDGET_MAPPED (tmp))
319 xgrab_shell = parent;
321 parent = GTK_MENU_SHELL (parent)->parent_menu_shell;
324 if (xgrab_shell && (!GTK_MENU_SHELL (xgrab_shell)->have_xgrab))
326 GdkCursor *cursor = gdk_cursor_new (GDK_ARROW);
328 GTK_MENU_SHELL (xgrab_shell)->have_xgrab =
329 (gdk_pointer_grab (xgrab_shell->window, TRUE,
330 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
331 GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK,
332 NULL, cursor, activate_time) == 0);
333 gdk_cursor_destroy (cursor);
336 gtk_grab_add (GTK_WIDGET (menu));
340 gtk_menu_popdown (GtkMenu *menu)
342 GtkMenuShell *menu_shell;
344 g_return_if_fail (menu != NULL);
345 g_return_if_fail (GTK_IS_MENU (menu));
347 menu_shell = GTK_MENU_SHELL (menu);
349 menu_shell->parent_menu_shell = NULL;
350 menu_shell->active = FALSE;
352 if (menu_shell->active_menu_item)
354 menu->old_active_menu_item = menu_shell->active_menu_item;
355 gtk_menu_item_deselect (GTK_MENU_ITEM (menu_shell->active_menu_item));
356 menu_shell->active_menu_item = NULL;
359 /* The X Grab, if present, will automatically be removed when we hide
361 gtk_widget_hide (GTK_WIDGET (menu));
362 menu_shell->have_xgrab = FALSE;
364 gtk_grab_remove (GTK_WIDGET (menu));
368 gtk_menu_get_active (GtkMenu *menu)
373 g_return_val_if_fail (menu != NULL, NULL);
374 g_return_val_if_fail (GTK_IS_MENU (menu), NULL);
376 if (!menu->old_active_menu_item)
379 children = GTK_MENU_SHELL (menu)->children;
383 child = children->data;
384 children = children->next;
386 if (GTK_BIN (child)->child)
391 menu->old_active_menu_item = child;
394 return menu->old_active_menu_item;
398 gtk_menu_set_active (GtkMenu *menu,
404 g_return_if_fail (menu != NULL);
405 g_return_if_fail (GTK_IS_MENU (menu));
407 tmp_list = g_list_nth (GTK_MENU_SHELL (menu)->children, index);
410 child = tmp_list->data;
411 if (GTK_BIN (child)->child)
412 menu->old_active_menu_item = child;
417 gtk_menu_set_accelerator_table (GtkMenu *menu,
418 GtkAcceleratorTable *table)
420 g_return_if_fail (menu != NULL);
421 g_return_if_fail (GTK_IS_MENU (menu));
423 if (menu->accelerator_table != table)
425 if (menu->accelerator_table)
426 gtk_accelerator_table_unref (menu->accelerator_table);
427 menu->accelerator_table = table;
428 if (menu->accelerator_table)
429 gtk_accelerator_table_ref (menu->accelerator_table);
435 gtk_menu_show (GtkWidget *widget)
437 g_return_if_fail (widget != NULL);
438 g_return_if_fail (GTK_IS_MENU (widget));
440 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
441 gtk_widget_map (widget);
445 gtk_menu_map (GtkWidget *widget)
448 GtkMenuShell *menu_shell;
451 GtkAllocation allocation;
454 g_return_if_fail (widget != NULL);
455 g_return_if_fail (GTK_IS_MENU (widget));
457 menu = GTK_MENU (widget);
458 menu_shell = GTK_MENU_SHELL (widget);
459 GTK_WIDGET_SET_FLAGS (menu_shell, GTK_MAPPED);
461 gtk_widget_size_request (widget, &widget->requisition);
463 if (menu_shell->menu_flag)
465 menu_shell->menu_flag = FALSE;
467 allocation.x = widget->allocation.x;
468 allocation.y = widget->allocation.y;
469 allocation.width = widget->requisition.width;
470 allocation.height = widget->requisition.height;
472 gtk_widget_size_allocate (widget, &allocation);
475 gdk_window_get_pointer (NULL, &x, &y, NULL);
477 if (menu->position_func)
478 (* menu->position_func) (menu, &x, &y, menu->position_func_data);
484 screen_width = gdk_screen_width ();
485 screen_height = gdk_screen_height ();
490 if ((x + widget->requisition.width) > screen_width)
491 x -= ((x + widget->requisition.width) - screen_width);
494 if ((y + widget->requisition.height) > screen_height)
495 y -= ((y + widget->requisition.height) - screen_height);
500 gdk_window_move_resize (widget->window, x, y,
501 widget->requisition.width,
502 widget->requisition.height);
504 children = menu_shell->children;
507 child = children->data;
508 children = children->next;
510 if (GTK_WIDGET_VISIBLE (child) && !GTK_WIDGET_MAPPED (child))
511 gtk_widget_map (child);
514 gdk_window_show (widget->window);
518 gtk_menu_unmap (GtkWidget *widget)
520 g_return_if_fail (widget != NULL);
521 g_return_if_fail (GTK_IS_MENU (widget));
523 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
524 gdk_window_hide (widget->window);
528 gtk_menu_realize (GtkWidget *widget)
530 GdkWindowAttr attributes;
531 gint attributes_mask;
533 g_return_if_fail (widget != NULL);
534 g_return_if_fail (GTK_IS_MENU (widget));
536 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
538 attributes.x = widget->allocation.x;
539 attributes.y = widget->allocation.y;
540 attributes.width = widget->allocation.width;
541 attributes.height = widget->allocation.height;
542 attributes.wclass = GDK_INPUT_OUTPUT;
543 attributes.visual = gtk_widget_get_visual (widget);
544 attributes.colormap = gtk_widget_get_colormap (widget);
545 attributes.window_type = GDK_WINDOW_TEMP;
546 attributes.event_mask = gtk_widget_get_events (widget);
547 attributes.event_mask |= (GDK_EXPOSURE_MASK |
551 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
552 widget->window = gdk_window_new (NULL, &attributes, attributes_mask);
553 gdk_window_set_user_data (widget->window, widget);
555 widget->style = gtk_style_attach (widget->style, widget->window);
556 gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
560 gtk_menu_size_request (GtkWidget *widget,
561 GtkRequisition *requisition)
564 GtkMenuShell *menu_shell;
567 gint max_accelerator_size;
568 gint max_toggle_size;
570 g_return_if_fail (widget != NULL);
571 g_return_if_fail (GTK_IS_MENU (widget));
572 g_return_if_fail (requisition != NULL);
574 menu = GTK_MENU (widget);
575 menu_shell = GTK_MENU_SHELL (widget);
577 requisition->width = 0;
578 requisition->height = 0;
580 max_accelerator_size = 0;
583 children = menu_shell->children;
586 child = children->data;
587 children = children->next;
589 if (GTK_WIDGET_VISIBLE (child))
591 GTK_MENU_ITEM (child)->show_submenu_indicator = TRUE;
592 gtk_widget_size_request (child, &child->requisition);
594 requisition->width = MAX (requisition->width, child->requisition.width);
595 requisition->height += child->requisition.height;
597 max_accelerator_size = MAX (max_accelerator_size, GTK_MENU_ITEM (child)->accelerator_size);
598 max_toggle_size = MAX (max_toggle_size, MENU_ITEM_CLASS (child)->toggle_size);
602 requisition->width += max_toggle_size + max_accelerator_size;
603 requisition->width += (GTK_CONTAINER (menu)->border_width +
604 widget->style->klass->xthickness) * 2;
605 requisition->height += (GTK_CONTAINER (menu)->border_width +
606 widget->style->klass->ythickness) * 2;
608 children = menu_shell->children;
611 child = children->data;
612 children = children->next;
614 GTK_MENU_ITEM (child)->accelerator_size = max_accelerator_size;
615 GTK_MENU_ITEM (child)->toggle_size = max_toggle_size;
620 gtk_menu_size_allocate (GtkWidget *widget,
621 GtkAllocation *allocation)
624 GtkMenuShell *menu_shell;
626 GtkAllocation child_allocation;
629 g_return_if_fail (widget != NULL);
630 g_return_if_fail (GTK_IS_MENU (widget));
631 g_return_if_fail (allocation != NULL);
633 menu = GTK_MENU (widget);
634 menu_shell = GTK_MENU_SHELL (widget);
636 widget->allocation = *allocation;
638 if (menu_shell->children)
640 child_allocation.x = (GTK_CONTAINER (menu)->border_width +
641 widget->style->klass->xthickness);
642 child_allocation.y = (GTK_CONTAINER (menu)->border_width +
643 widget->style->klass->ythickness);
644 child_allocation.width = MAX (1, allocation->width - child_allocation.x * 2);
646 children = menu_shell->children;
649 child = children->data;
650 children = children->next;
652 if (GTK_WIDGET_VISIBLE (child))
654 child_allocation.height = child->requisition.height;
656 gtk_widget_size_allocate (child, &child_allocation);
658 child_allocation.y += child_allocation.height;
665 gtk_menu_paint (GtkWidget *widget)
667 g_return_if_fail (widget != NULL);
668 g_return_if_fail (GTK_IS_MENU (widget));
670 if (GTK_WIDGET_DRAWABLE (widget))
672 gtk_draw_shadow (widget->style,
677 widget->allocation.width,
678 widget->allocation.height);
683 gtk_menu_draw (GtkWidget *widget,
686 GtkMenuShell *menu_shell;
688 GdkRectangle child_area;
691 g_return_if_fail (widget != NULL);
692 g_return_if_fail (GTK_IS_MENU (widget));
693 g_return_if_fail (area != NULL);
695 if (GTK_WIDGET_DRAWABLE (widget))
697 gtk_menu_paint (widget);
699 menu_shell = GTK_MENU_SHELL (widget);
701 children = menu_shell->children;
704 child = children->data;
705 children = children->next;
707 if (gtk_widget_intersect (child, area, &child_area))
708 gtk_widget_draw (child, &child_area);
714 gtk_menu_expose (GtkWidget *widget,
715 GdkEventExpose *event)
717 GtkMenuShell *menu_shell;
719 GdkEventExpose child_event;
722 g_return_val_if_fail (widget != NULL, FALSE);
723 g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
724 g_return_val_if_fail (event != NULL, FALSE);
726 if (GTK_WIDGET_DRAWABLE (widget))
728 gtk_menu_paint (widget);
730 menu_shell = GTK_MENU_SHELL (widget);
731 child_event = *event;
733 children = menu_shell->children;
736 child = children->data;
737 children = children->next;
739 if (GTK_WIDGET_NO_WINDOW (child) &&
740 gtk_widget_intersect (child, &event->area, &child_event.area))
741 gtk_widget_event (child, (GdkEvent*) &child_event);
749 gtk_menu_configure (GtkWidget *widget,
750 GdkEventConfigure *event)
752 GtkAllocation allocation;
754 g_return_val_if_fail (widget != NULL, FALSE);
755 g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
756 g_return_val_if_fail (event != NULL, FALSE);
758 /* If the window was merely moved, do nothing */
759 if ((widget->allocation.width == event->width) &&
760 (widget->allocation.height == event->height))
763 if (GTK_MENU_SHELL (widget)->menu_flag)
765 GTK_MENU_SHELL (widget)->menu_flag = FALSE;
769 allocation.width = event->width;
770 allocation.height = event->height;
772 gtk_widget_size_allocate (widget, &allocation);
779 gtk_menu_key_press (GtkWidget *widget,
782 GtkAllocation allocation;
783 GtkAcceleratorTable *table;
787 g_return_val_if_fail (widget != NULL, FALSE);
788 g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
789 g_return_val_if_fail (event != NULL, FALSE);
791 delete = ((event->keyval == GDK_Delete) ||
792 (event->keyval == GDK_BackSpace));
794 if (delete || ((event->keyval >= 0x20) && (event->keyval <= 0xFF)))
796 GtkMenuShell *menu_shell;
798 menu_shell = GTK_MENU_SHELL (widget);
800 if (menu_shell->active_menu_item && GTK_BIN (menu_shell->active_menu_item)->child)
802 GtkMenuItem *menu_item;
804 menu_item = GTK_MENU_ITEM (menu_shell->active_menu_item);
807 gtk_container_block_resize (GTK_CONTAINER (widget));
810 /* if the menu item currently has an accelerator then we'll
811 * remove it before we do anything else.
813 if (menu_item->accelerator_signal)
815 signame = gtk_signal_name (menu_item->accelerator_signal);
816 table = gtk_accelerator_table_find (GTK_OBJECT (widget),
818 menu_item->accelerator_key,
819 menu_item->accelerator_mods);
821 table = GTK_MENU (widget)->accelerator_table;
822 gtk_widget_remove_accelerator (GTK_WIDGET (menu_item),
827 table = GTK_MENU (widget)->accelerator_table;
829 /* if we aren't simply deleting the accelerator, then we'll install
833 gtk_widget_install_accelerator (GTK_WIDGET (menu_item),
835 toupper (event->keyval),
838 /* check and see if the menu has changed size. */
839 gtk_widget_size_request (widget, &widget->requisition);
841 allocation.x = widget->allocation.x;
842 allocation.y = widget->allocation.y;
843 allocation.width = widget->requisition.width;
844 allocation.height = widget->requisition.height;
846 if ((allocation.width == widget->allocation.width) &&
847 (allocation.height == widget->allocation.height))
849 gtk_widget_queue_draw (widget);
853 gtk_widget_size_allocate (GTK_WIDGET (widget), &allocation);
854 gtk_menu_map (widget);
857 /* unblock resizes */
858 gtk_container_unblock_resize (GTK_CONTAINER (widget));
866 gtk_menu_need_resize (GtkContainer *container)
868 GtkAllocation allocation;
870 g_return_val_if_fail (container != NULL, FALSE);
871 g_return_val_if_fail (GTK_IS_MENU (container), FALSE);
873 if (GTK_WIDGET_VISIBLE (container))
875 GTK_MENU_SHELL (container)->menu_flag = FALSE;
877 gtk_widget_size_request (GTK_WIDGET (container),
878 >K_WIDGET (container)->requisition);
880 allocation.x = GTK_WIDGET (container)->allocation.x;
881 allocation.y = GTK_WIDGET (container)->allocation.y;
882 allocation.width = GTK_WIDGET (container)->requisition.width;
883 allocation.height = GTK_WIDGET (container)->requisition.height;
885 gtk_widget_size_allocate (GTK_WIDGET (container), &allocation);
889 GTK_MENU_SHELL (container)->menu_flag = TRUE;
896 gtk_menu_deactivate (GtkMenuShell *menu_shell)
900 g_return_if_fail (menu_shell != NULL);
901 g_return_if_fail (GTK_IS_MENU (menu_shell));
903 parent = menu_shell->parent_menu_shell;
905 menu_shell->activate_time = 0;
906 gtk_menu_popdown (GTK_MENU (menu_shell));
909 gtk_menu_shell_deactivate (GTK_MENU_SHELL (parent));
914 gtk_menu_show_all (GtkWidget *widget)
916 GtkContainer *container;
918 g_return_if_fail (widget != NULL);
919 g_return_if_fail (GTK_IS_MENU (widget));
920 container = GTK_CONTAINER (widget);
922 /* Show children, but not self. */
923 gtk_container_foreach (container, (GtkCallback) gtk_widget_show_all, NULL);
928 gtk_menu_hide_all (GtkWidget *widget)
930 GtkContainer *container;
932 g_return_if_fail (widget != NULL);
933 g_return_if_fail (GTK_IS_MENU (widget));
934 container = GTK_CONTAINER (widget);
936 /* Hide children, but not self. */
937 gtk_container_foreach (container, (GtkCallback) gtk_widget_hide_all, NULL);