]> Pileus Git - ~andy/gtk/blob - gtk/gtkoptionmenu.c
boy! did i really modify that many files?
[~andy/gtk] / gtk / gtkoptionmenu.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
14  * You should have received a copy of the GNU Library 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.
18  */
19 #include "gtkmenu.h"
20 #include "gtkmenuitem.h"
21 #include "gtkoptionmenu.h"
22 #include "gtksignal.h"
23
24
25 #define CHILD_LEFT_SPACING        5
26 #define CHILD_RIGHT_SPACING       1
27 #define CHILD_TOP_SPACING         1
28 #define CHILD_BOTTOM_SPACING      1
29 #define OPTION_INDICATOR_WIDTH    12
30 #define OPTION_INDICATOR_HEIGHT   8
31 #define OPTION_INDICATOR_SPACING  2
32
33
34 static void gtk_option_menu_class_init      (GtkOptionMenuClass *klass);
35 static void gtk_option_menu_init            (GtkOptionMenu      *option_menu);
36 static void gtk_option_menu_destroy         (GtkObject          *object);
37 static void gtk_option_menu_size_request    (GtkWidget          *widget,
38                                              GtkRequisition     *requisition);
39 static void gtk_option_menu_size_allocate   (GtkWidget          *widget,
40                                              GtkAllocation      *allocation);
41 static void gtk_option_menu_paint           (GtkWidget          *widget,
42                                              GdkRectangle       *area);
43 static void gtk_option_menu_draw            (GtkWidget          *widget,
44                                              GdkRectangle       *area);
45 static gint gtk_option_menu_expose          (GtkWidget          *widget,
46                                              GdkEventExpose     *event);
47 static gint gtk_option_menu_button_press    (GtkWidget          *widget,
48                                              GdkEventButton     *event);
49 static void gtk_option_menu_deactivate      (GtkMenuShell       *menu_shell,
50                                              GtkOptionMenu      *option_menu);
51 static void gtk_option_menu_update_contents (GtkOptionMenu      *option_menu);
52 static void gtk_option_menu_remove_contents (GtkOptionMenu      *option_menu);
53 static void gtk_option_menu_calc_size       (GtkOptionMenu      *option_menu);
54 static void gtk_option_menu_position        (GtkMenu            *menu,
55                                              gint               *x,
56                                              gint               *y,
57                                              gpointer            user_data);
58 static void gtk_option_menu_show_all        (GtkWidget          *widget);
59 static void gtk_option_menu_hide_all        (GtkWidget          *widget);
60 static GtkType gtk_option_menu_child_type   (GtkContainer       *container);
61
62
63 static GtkButtonClass *parent_class = NULL;
64
65
66 GtkType
67 gtk_option_menu_get_type (void)
68 {
69   static GtkType option_menu_type = 0;
70
71   if (!option_menu_type)
72     {
73       GtkTypeInfo option_menu_info =
74       {
75         "GtkOptionMenu",
76         sizeof (GtkOptionMenu),
77         sizeof (GtkOptionMenuClass),
78         (GtkClassInitFunc) gtk_option_menu_class_init,
79         (GtkObjectInitFunc) gtk_option_menu_init,
80         (GtkArgSetFunc) NULL,
81         (GtkArgGetFunc) NULL,
82       };
83
84       option_menu_type = gtk_type_unique (gtk_button_get_type (), &option_menu_info);
85     }
86
87   return option_menu_type;
88 }
89
90 static void
91 gtk_option_menu_class_init (GtkOptionMenuClass *class)
92 {
93   GtkObjectClass *object_class;
94   GtkWidgetClass *widget_class;
95   GtkButtonClass *button_class;
96   GtkContainerClass *container_class;
97
98   object_class = (GtkObjectClass*) class;
99   widget_class = (GtkWidgetClass*) class;
100   button_class = (GtkButtonClass*) class;
101   container_class = (GtkContainerClass*) class;
102
103   parent_class = gtk_type_class (gtk_button_get_type ());
104
105   object_class->destroy = gtk_option_menu_destroy;
106
107   widget_class->draw = gtk_option_menu_draw;
108   widget_class->draw_focus = NULL;
109   widget_class->size_request = gtk_option_menu_size_request;
110   widget_class->size_allocate = gtk_option_menu_size_allocate;
111   widget_class->expose_event = gtk_option_menu_expose;
112   widget_class->button_press_event = gtk_option_menu_button_press;
113   widget_class->show_all = gtk_option_menu_show_all;
114   widget_class->hide_all = gtk_option_menu_hide_all;
115
116   container_class->child_type = gtk_option_menu_child_type;
117 }
118
119 static GtkType
120 gtk_option_menu_child_type (GtkContainer       *container)
121 {
122   return GTK_TYPE_NONE;
123 }
124
125 static void
126 gtk_option_menu_init (GtkOptionMenu *option_menu)
127 {
128   GTK_WIDGET_UNSET_FLAGS (option_menu, GTK_CAN_FOCUS);
129
130   option_menu->menu = NULL;
131   option_menu->menu_item = NULL;
132   option_menu->width = 0;
133   option_menu->height = 0;
134 }
135
136 GtkWidget*
137 gtk_option_menu_new (void)
138 {
139   return GTK_WIDGET (gtk_type_new (gtk_option_menu_get_type ()));
140 }
141
142 GtkWidget*
143 gtk_option_menu_get_menu (GtkOptionMenu *option_menu)
144 {
145   g_return_val_if_fail (option_menu != NULL, NULL);
146   g_return_val_if_fail (GTK_IS_OPTION_MENU (option_menu), NULL);
147
148   return option_menu->menu;
149 }
150
151 static void
152 gtk_option_menu_detacher (GtkWidget     *widget,
153                           GtkMenu       *menu)
154 {
155   GtkOptionMenu *option_menu;
156
157   g_return_if_fail (widget != NULL);
158   g_return_if_fail (GTK_IS_OPTION_MENU (widget));
159
160   option_menu = GTK_OPTION_MENU (widget);
161   g_return_if_fail (option_menu->menu == (GtkWidget*) menu);
162
163   gtk_option_menu_remove_contents (option_menu);
164   gtk_signal_disconnect_by_data (GTK_OBJECT (option_menu->menu),
165                                  option_menu);
166   
167   option_menu->menu = NULL;
168 }
169
170 void
171 gtk_option_menu_set_menu (GtkOptionMenu *option_menu,
172                           GtkWidget     *menu)
173 {
174   g_return_if_fail (option_menu != NULL);
175   g_return_if_fail (GTK_IS_OPTION_MENU (option_menu));
176   g_return_if_fail (menu != NULL);
177   g_return_if_fail (GTK_IS_MENU (menu));
178
179   if (option_menu->menu != menu)
180     {
181       gtk_option_menu_remove_menu (option_menu);
182
183       option_menu->menu = menu;
184       gtk_menu_attach_to_widget (GTK_MENU (menu),
185                                  GTK_WIDGET (option_menu),
186                                  gtk_option_menu_detacher);
187
188       gtk_option_menu_calc_size (option_menu);
189
190       gtk_signal_connect (GTK_OBJECT (option_menu->menu), "deactivate",
191                           (GtkSignalFunc) gtk_option_menu_deactivate,
192                           option_menu);
193
194       if (GTK_WIDGET (option_menu)->parent)
195         gtk_widget_queue_resize (GTK_WIDGET (option_menu));
196
197       gtk_option_menu_update_contents (option_menu);
198     }
199 }
200
201 void
202 gtk_option_menu_remove_menu (GtkOptionMenu *option_menu)
203 {
204   g_return_if_fail (option_menu != NULL);
205   g_return_if_fail (GTK_IS_OPTION_MENU (option_menu));
206
207   if (option_menu->menu)
208     gtk_menu_detach (GTK_MENU (option_menu->menu));
209 }
210
211 void
212 gtk_option_menu_set_history (GtkOptionMenu *option_menu,
213                              guint          index)
214 {
215   GtkWidget *menu_item;
216
217   g_return_if_fail (option_menu != NULL);
218   g_return_if_fail (GTK_IS_OPTION_MENU (option_menu));
219
220   if (option_menu->menu)
221     {
222       gtk_menu_set_active (GTK_MENU (option_menu->menu), index);
223       menu_item = gtk_menu_get_active (GTK_MENU (option_menu->menu));
224
225       if (menu_item != option_menu->menu_item)
226         {
227           gtk_option_menu_remove_contents (option_menu);
228           gtk_option_menu_update_contents (option_menu);
229         }
230     }
231 }
232
233
234 static void
235 gtk_option_menu_destroy (GtkObject *object)
236 {
237   GtkOptionMenu *option_menu;
238
239   g_return_if_fail (object != NULL);
240   g_return_if_fail (GTK_IS_OPTION_MENU (object));
241
242   option_menu = GTK_OPTION_MENU (object);
243
244   if (option_menu->menu)
245     gtk_widget_destroy (option_menu->menu);
246
247   if (GTK_OBJECT_CLASS (parent_class)->destroy)
248     (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
249 }
250
251 static void
252 gtk_option_menu_size_request (GtkWidget      *widget,
253                               GtkRequisition *requisition)
254 {
255   GtkOptionMenu *option_menu;
256   gint tmp;
257
258   g_return_if_fail (widget != NULL);
259   g_return_if_fail (GTK_IS_OPTION_MENU (widget));
260   g_return_if_fail (requisition != NULL);
261
262   option_menu = GTK_OPTION_MENU (widget);
263
264   requisition->width = ((GTK_CONTAINER (widget)->border_width +
265                          GTK_WIDGET (widget)->style->klass->xthickness) * 2 +
266                         option_menu->width +
267                         OPTION_INDICATOR_WIDTH +
268                         OPTION_INDICATOR_SPACING * 5 +
269                         CHILD_LEFT_SPACING + CHILD_RIGHT_SPACING);
270   requisition->height = ((GTK_CONTAINER (widget)->border_width +
271                           GTK_WIDGET (widget)->style->klass->ythickness) * 2 +
272                          option_menu->height +
273                          CHILD_TOP_SPACING + CHILD_BOTTOM_SPACING);
274
275   tmp = (requisition->height - option_menu->height +
276          OPTION_INDICATOR_HEIGHT + OPTION_INDICATOR_SPACING * 2);
277   requisition->height = MAX (requisition->height, tmp);
278 }
279
280 static void
281 gtk_option_menu_size_allocate (GtkWidget     *widget,
282                                GtkAllocation *allocation)
283 {
284   GtkWidget *child;
285   GtkAllocation child_allocation;
286
287   g_return_if_fail (widget != NULL);
288   g_return_if_fail (GTK_IS_OPTION_MENU (widget));
289   g_return_if_fail (allocation != NULL);
290
291   widget->allocation = *allocation;
292   if (GTK_WIDGET_REALIZED (widget))
293     gdk_window_move_resize (widget->window,
294                             allocation->x, allocation->y,
295                             allocation->width, allocation->height);
296
297   child = GTK_BUTTON (widget)->child;
298   if (child && GTK_WIDGET_VISIBLE (child))
299     {
300       child_allocation.x = (GTK_CONTAINER (widget)->border_width +
301                             GTK_WIDGET (widget)->style->klass->xthickness);
302       child_allocation.y = (GTK_CONTAINER (widget)->border_width +
303                             GTK_WIDGET (widget)->style->klass->ythickness);
304       child_allocation.width = (allocation->width - child_allocation.x * 2 -
305                                 OPTION_INDICATOR_WIDTH - OPTION_INDICATOR_SPACING * 5 -
306                                 CHILD_LEFT_SPACING - CHILD_RIGHT_SPACING);
307       child_allocation.height = (allocation->height - child_allocation.y * 2 -
308                                  CHILD_TOP_SPACING - CHILD_BOTTOM_SPACING);
309       child_allocation.x += CHILD_LEFT_SPACING;
310       child_allocation.y += CHILD_RIGHT_SPACING;
311
312       gtk_widget_size_allocate (child, &child_allocation);
313     }
314 }
315
316 static void
317 gtk_option_menu_paint (GtkWidget    *widget,
318                        GdkRectangle *area)
319 {
320   GdkRectangle restrict_area;
321   GdkRectangle new_area;
322
323   g_return_if_fail (widget != NULL);
324   g_return_if_fail (GTK_IS_OPTION_MENU (widget));
325   g_return_if_fail (area != NULL);
326
327   if (GTK_WIDGET_DRAWABLE (widget))
328     {
329       restrict_area.x = GTK_CONTAINER (widget)->border_width;
330       restrict_area.y = GTK_CONTAINER (widget)->border_width;
331       restrict_area.width = widget->allocation.width - restrict_area.x * 2;
332       restrict_area.height = widget->allocation.height - restrict_area.y * 2;
333
334       if (gdk_rectangle_intersect (area, &restrict_area, &new_area))
335         {
336           gtk_style_set_background (widget->style, widget->window, GTK_WIDGET_STATE (widget));
337           gdk_window_clear_area (widget->window,
338                                  new_area.x, new_area.y,
339                                  new_area.width, new_area.height);
340
341           gtk_draw_shadow (widget->style, widget->window,
342                            GTK_WIDGET_STATE (widget), GTK_SHADOW_OUT,
343                            restrict_area.x, restrict_area.y,
344                            restrict_area.width, restrict_area.height);
345
346           gtk_draw_shadow (widget->style, widget->window,
347                            GTK_WIDGET_STATE (widget), GTK_SHADOW_OUT,
348                            restrict_area.x + restrict_area.width - restrict_area.x -
349                            OPTION_INDICATOR_WIDTH - OPTION_INDICATOR_SPACING * 4,
350                            restrict_area.y + (restrict_area.height - OPTION_INDICATOR_HEIGHT) / 2,
351                            OPTION_INDICATOR_WIDTH, OPTION_INDICATOR_HEIGHT);
352         }
353     }
354 }
355
356 static void
357 gtk_option_menu_draw (GtkWidget    *widget,
358                       GdkRectangle *area)
359 {
360   GtkWidget *child;
361   GdkRectangle child_area;
362
363   g_return_if_fail (widget != NULL);
364   g_return_if_fail (GTK_IS_OPTION_MENU (widget));
365   g_return_if_fail (area != NULL);
366
367   if (GTK_WIDGET_DRAWABLE (widget))
368     {
369       gtk_option_menu_paint (widget, area);
370
371       child = GTK_BUTTON (widget)->child;
372       if (child && gtk_widget_intersect (child, area, &child_area))
373         gtk_widget_draw (child, &child_area);
374     }
375 }
376
377 static gint
378 gtk_option_menu_expose (GtkWidget      *widget,
379                         GdkEventExpose *event)
380 {
381   GtkWidget *child;
382   GdkEventExpose child_event;
383   gint remove_child;
384
385   g_return_val_if_fail (widget != NULL, FALSE);
386   g_return_val_if_fail (GTK_IS_OPTION_MENU (widget), FALSE);
387   g_return_val_if_fail (event != NULL, FALSE);
388
389   if (GTK_WIDGET_DRAWABLE (widget))
390     {
391       gtk_option_menu_paint (widget, &event->area);
392
393
394       /* The following code tries to draw the child in two places at
395        * once. It fails miserably for several reasons
396        *
397        * - If the child is not no-window, removing generates
398        *   more expose events. Bad, bad, bad.
399        * 
400        * - Even if the child is no-window, removing it now (properly)
401        *   clears the space where it was, so it does no good
402        */
403       
404 #if 0
405       remove_child = FALSE;
406       child = GTK_BUTTON (widget)->child;
407
408       if (!child)
409         {
410           if (!GTK_OPTION_MENU (widget)->menu)
411             return FALSE;
412           gtk_option_menu_update_contents (GTK_OPTION_MENU (widget));
413           child = GTK_BUTTON (widget)->child;
414           if (!child)
415             return FALSE;
416           remove_child = TRUE;
417         }
418
419       child_event = *event;
420
421       if (GTK_WIDGET_NO_WINDOW (child) &&
422           gtk_widget_intersect (child, &event->area, &child_event.area))
423         gtk_widget_event (child, (GdkEvent*) &child_event);
424
425       if (remove_child)
426         gtk_option_menu_remove_contents (GTK_OPTION_MENU (widget));
427 #else
428       remove_child = FALSE;
429       child = GTK_BUTTON (widget)->child;
430       child_event = *event;
431       if (child && GTK_WIDGET_NO_WINDOW (child) &&
432           gtk_widget_intersect (child, &event->area, &child_event.area))
433         gtk_widget_event (child, (GdkEvent*) &child_event);
434
435 #endif /* 0 */
436     }
437
438   return FALSE;
439 }
440
441 static gint
442 gtk_option_menu_button_press (GtkWidget      *widget,
443                               GdkEventButton *event)
444 {
445   GtkOptionMenu *option_menu;
446
447   g_return_val_if_fail (widget != NULL, FALSE);
448   g_return_val_if_fail (GTK_IS_OPTION_MENU (widget), FALSE);
449   g_return_val_if_fail (event != NULL, FALSE);
450
451   if ((event->type == GDK_BUTTON_PRESS) &&
452       (event->button == 1))
453     {
454       option_menu = GTK_OPTION_MENU (widget);
455       gtk_option_menu_remove_contents (option_menu);
456       gtk_menu_popup (GTK_MENU (option_menu->menu), NULL, NULL,
457                       gtk_option_menu_position, option_menu,
458                       event->button, event->time);
459     }
460
461   return FALSE;
462 }
463
464 static void
465 gtk_option_menu_deactivate (GtkMenuShell  *menu_shell,
466                             GtkOptionMenu *option_menu)
467 {
468   g_return_if_fail (menu_shell != NULL);
469   g_return_if_fail (option_menu != NULL);
470   g_return_if_fail (GTK_IS_OPTION_MENU (option_menu));
471
472   gtk_option_menu_update_contents (option_menu);
473 }
474
475 static void
476 gtk_option_menu_update_contents (GtkOptionMenu *option_menu)
477 {
478   GtkWidget *child;
479
480   g_return_if_fail (option_menu != NULL);
481   g_return_if_fail (GTK_IS_OPTION_MENU (option_menu));
482
483   if (option_menu->menu)
484     {
485       gtk_option_menu_remove_contents (option_menu);
486
487       option_menu->menu_item = gtk_menu_get_active (GTK_MENU (option_menu->menu));
488       if (option_menu->menu_item)
489         {
490           gtk_widget_ref (option_menu->menu_item);
491           child = GTK_BIN (option_menu->menu_item)->child;
492           if (child)
493             {
494               gtk_container_block_resize (GTK_CONTAINER (option_menu));
495               if (GTK_BUTTON (option_menu)->child)
496                 gtk_container_remove (GTK_CONTAINER (option_menu),
497                                       GTK_BUTTON (option_menu)->child);
498               if (GTK_WIDGET (option_menu)->state != child->state)
499                 gtk_widget_set_state (child, GTK_WIDGET (option_menu)->state);
500               gtk_widget_reparent (child, GTK_WIDGET (option_menu));
501               gtk_container_unblock_resize (GTK_CONTAINER (option_menu));
502             }
503
504           gtk_widget_size_request (child, &child->requisition);
505           gtk_widget_size_allocate (GTK_WIDGET (option_menu),
506                                     &(GTK_WIDGET (option_menu)->allocation));
507
508           if (GTK_WIDGET_DRAWABLE (option_menu))
509             gtk_widget_queue_draw (GTK_WIDGET (option_menu));
510         }
511     }
512 }
513
514 static void
515 gtk_option_menu_remove_contents (GtkOptionMenu *option_menu)
516 {
517   g_return_if_fail (option_menu != NULL);
518   g_return_if_fail (GTK_IS_OPTION_MENU (option_menu));
519
520   if (GTK_BUTTON (option_menu)->child)
521     {
522       gtk_container_block_resize (GTK_CONTAINER (option_menu));
523       if (GTK_WIDGET (option_menu->menu_item)->state != GTK_BUTTON (option_menu)->child->state)
524         gtk_widget_set_state (GTK_BUTTON (option_menu)->child,
525                               GTK_WIDGET (option_menu->menu_item)->state);
526       gtk_widget_reparent (GTK_BUTTON (option_menu)->child, option_menu->menu_item);
527       gtk_widget_unref (option_menu->menu_item);
528       option_menu->menu_item = NULL;
529       gtk_container_unblock_resize (GTK_CONTAINER (option_menu));
530     }
531 }
532
533 static void
534 gtk_option_menu_calc_size (GtkOptionMenu *option_menu)
535 {
536   GtkWidget *child;
537   GList *children;
538
539   g_return_if_fail (option_menu != NULL);
540   g_return_if_fail (GTK_IS_OPTION_MENU (option_menu));
541
542   option_menu->width = 0;
543   option_menu->height = 0;
544
545   if (option_menu->menu)
546     {
547       children = GTK_MENU_SHELL (option_menu->menu)->children;
548       while (children)
549         {
550           child = children->data;
551           children = children->next;
552
553           if (GTK_WIDGET_VISIBLE (child))
554             {
555               gtk_widget_size_request (child, &child->requisition);
556
557               option_menu->width = MAX (option_menu->width, child->requisition.width);
558               option_menu->height = MAX (option_menu->height, child->requisition.height);
559             }
560         }
561     }
562 }
563
564 static void
565 gtk_option_menu_position (GtkMenu  *menu,
566                           gint     *x,
567                           gint     *y,
568                           gpointer  user_data)
569 {
570   GtkOptionMenu *option_menu;
571   GtkWidget *active;
572   GtkWidget *child;
573   GList *children;
574   gint shift_menu;
575   gint screen_width;
576   gint screen_height;
577   gint menu_xpos;
578   gint menu_ypos;
579   gint width;
580   gint height;
581
582   g_return_if_fail (user_data != NULL);
583   g_return_if_fail (GTK_IS_OPTION_MENU (user_data));
584
585   option_menu = GTK_OPTION_MENU (user_data);
586
587   width = GTK_WIDGET (menu)->allocation.width;
588   height = GTK_WIDGET (menu)->allocation.height;
589
590   active = gtk_menu_get_active (GTK_MENU (option_menu->menu));
591   children = GTK_MENU_SHELL (option_menu->menu)->children;
592   gdk_window_get_origin (GTK_WIDGET (option_menu)->window, &menu_xpos, &menu_ypos);
593
594   menu_ypos += GTK_WIDGET (option_menu)->allocation.height / 2 - 2;
595
596   if (active != NULL)
597     menu_ypos -= active->requisition.height / 2;
598
599   while (children)
600     {
601       child = children->data;
602
603       if (active == child)
604         break;
605
606       menu_ypos -= child->allocation.height;
607       children = children->next;
608     }
609
610   screen_width = gdk_screen_width ();
611   screen_height = gdk_screen_height ();
612
613   shift_menu = FALSE;
614   if (menu_ypos < 0)
615     {
616       menu_ypos = 0;
617       shift_menu = TRUE;
618     }
619   else if ((menu_ypos + height) > screen_height)
620     {
621       menu_ypos -= ((menu_ypos + height) - screen_height);
622       shift_menu = TRUE;
623     }
624
625   if (shift_menu)
626     {
627       if ((menu_xpos + GTK_WIDGET (option_menu)->allocation.width + width) <= screen_width)
628         menu_xpos += GTK_WIDGET (option_menu)->allocation.width;
629       else
630         menu_xpos -= width;
631     }
632
633   if (menu_xpos < 0)
634     menu_xpos = 0;
635   else if ((menu_xpos + width) > screen_width)
636     menu_xpos -= ((menu_xpos + width) - screen_width);
637
638   *x = menu_xpos;
639   *y = menu_ypos;
640 }
641
642
643 static void
644 gtk_option_menu_show_all (GtkWidget *widget)
645 {
646   GtkContainer *container;
647   GtkOptionMenu *option_menu;
648   
649   g_return_if_fail (widget != NULL);
650   g_return_if_fail (GTK_IS_OPTION_MENU (widget));
651   container = GTK_CONTAINER (widget);
652   option_menu = GTK_OPTION_MENU (widget);
653
654   gtk_widget_show (widget);
655   gtk_container_foreach (container, (GtkCallback) gtk_widget_show_all, NULL);
656   if (option_menu->menu)
657     gtk_widget_show_all (option_menu->menu);
658   if (option_menu->menu_item)
659     gtk_widget_show_all (option_menu->menu_item);
660 }
661
662
663 static void
664 gtk_option_menu_hide_all (GtkWidget *widget)
665 {
666   GtkContainer *container;
667
668   g_return_if_fail (widget != NULL);
669   g_return_if_fail (GTK_IS_OPTION_MENU (widget));
670   container = GTK_CONTAINER (widget);
671
672   gtk_widget_hide (widget);
673   gtk_container_foreach (container, (GtkCallback) gtk_widget_hide_all, NULL);
674 }
675