]> Pileus Git - ~andy/gtk/blob - gtk/gtktoolbar.c
Re-indented to GNU style to be consistent with the rest of Gtk - Federico
[~andy/gtk] / gtk / gtktoolbar.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  * GtkToolbar copyright (C) Federico Mena
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the Free
17  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #include "gtkbutton.h"
21 #include "gtklabel.h"
22 #include "gtkvbox.h"
23 #include "gtktoolbar.h"
24
25
26 #define DEFAULT_SPACE_SIZE 5
27
28
29 enum {
30   ORIENTATION_CHANGED,
31   STYLE_CHANGED,
32   LAST_SIGNAL
33 };
34
35
36 typedef enum
37 {
38   CHILD_SPACE,
39   CHILD_BUTTON,
40   CHILD_WIDGET
41 } ChildType;
42
43 typedef struct
44 {
45   ChildType type;
46   GtkWidget *widget;
47   GtkWidget *icon;
48   GtkWidget *label;
49 } Child;
50
51
52 typedef void (*GtkToolbarSignal1) (GtkObject *object,
53                                    gint       arg1,
54                                    gpointer   data);
55
56 static void gtk_toolbar_marshal_signal_1 (GtkObject     *object,
57                                           GtkSignalFunc  func,
58                                           gpointer       func_data,
59                                           GtkArg        *args);
60
61
62 static void gtk_toolbar_class_init               (GtkToolbarClass *class);
63 static void gtk_toolbar_init                     (GtkToolbar      *toolbar);
64 static void gtk_toolbar_destroy                  (GtkObject       *object);
65 static void gtk_toolbar_map                      (GtkWidget       *widget);
66 static void gtk_toolbar_unmap                    (GtkWidget       *widget);
67 static void gtk_toolbar_draw                     (GtkWidget       *widget,
68                                                   GdkRectangle    *area);
69 static gint gtk_toolbar_expose                   (GtkWidget       *widget,
70                                                   GdkEventExpose  *event);
71 static void gtk_toolbar_size_request             (GtkWidget       *widget,
72                                                   GtkRequisition  *requisition);
73 static void gtk_toolbar_size_allocate            (GtkWidget       *widget,
74                                                   GtkAllocation   *allocation);
75 static void gtk_toolbar_add                      (GtkContainer    *container,
76                                                   GtkWidget       *widget);
77 static void gtk_toolbar_remove                   (GtkContainer    *container,
78                                                   GtkWidget       *widget);
79 static void gtk_toolbar_foreach                  (GtkContainer    *container,
80                                                   GtkCallback      callback,
81                                                   gpointer         callback_data);
82 static void gtk_real_toolbar_orientation_changed (GtkToolbar      *toolbar,
83                                                   GtkOrientation   orientation);
84 static void gtk_real_toolbar_style_changed       (GtkToolbar      *toolbar,
85                                                   GtkToolbarStyle  style);
86
87
88 static GtkContainerClass *parent_class;
89
90 static gint toolbar_signals[LAST_SIGNAL] = { 0 };
91
92
93 guint
94 gtk_toolbar_get_type (void)
95 {
96   static guint toolbar_type = 0;
97
98   if (!toolbar_type)
99     {
100       GtkTypeInfo toolbar_info =
101       {
102         "GtkToolbar",
103         sizeof (GtkToolbar),
104         sizeof (GtkToolbarClass),
105         (GtkClassInitFunc) gtk_toolbar_class_init,
106         (GtkObjectInitFunc) gtk_toolbar_init,
107         (GtkArgFunc) NULL
108       };
109
110       toolbar_type = gtk_type_unique (gtk_container_get_type (), &toolbar_info);
111     }
112
113   return toolbar_type;
114 }
115
116 static void
117 gtk_toolbar_class_init (GtkToolbarClass *class)
118 {
119   GtkObjectClass *object_class;
120   GtkWidgetClass *widget_class;
121   GtkContainerClass *container_class;
122
123   object_class = (GtkObjectClass *) class;
124   widget_class = (GtkWidgetClass *) class;
125   container_class = (GtkContainerClass *) class;
126
127   parent_class = gtk_type_class (gtk_container_get_type ());
128
129   toolbar_signals[ORIENTATION_CHANGED] =
130     gtk_signal_new ("orientation_changed",
131                     GTK_RUN_FIRST,
132                     object_class->type,
133                     GTK_SIGNAL_OFFSET (GtkToolbarClass, orientation_changed),
134                     gtk_toolbar_marshal_signal_1,
135                     GTK_TYPE_NONE, 1,
136                     GTK_TYPE_INT);
137   toolbar_signals[STYLE_CHANGED] =
138     gtk_signal_new ("style_changed",
139                     GTK_RUN_FIRST,
140                     object_class->type,
141                     GTK_SIGNAL_OFFSET (GtkToolbarClass, style_changed),
142                     gtk_toolbar_marshal_signal_1,
143                     GTK_TYPE_NONE, 1,
144                     GTK_TYPE_INT);
145
146   gtk_object_class_add_signals (object_class, toolbar_signals, LAST_SIGNAL);
147
148   object_class->destroy = gtk_toolbar_destroy;
149
150   widget_class->map = gtk_toolbar_map;
151   widget_class->unmap = gtk_toolbar_unmap;
152   widget_class->draw = gtk_toolbar_draw;
153   widget_class->expose_event = gtk_toolbar_expose;
154   widget_class->size_request = gtk_toolbar_size_request;
155   widget_class->size_allocate = gtk_toolbar_size_allocate;
156
157   container_class->add = gtk_toolbar_add;
158   container_class->remove = gtk_toolbar_remove;
159   container_class->foreach = gtk_toolbar_foreach;
160
161   class->orientation_changed = gtk_real_toolbar_orientation_changed;
162   class->style_changed = gtk_real_toolbar_style_changed;
163 }
164
165 static void
166 gtk_toolbar_init (GtkToolbar *toolbar)
167 {
168   GTK_WIDGET_SET_FLAGS (toolbar, GTK_NO_WINDOW);
169
170   toolbar->num_children = 0;
171   toolbar->children     = NULL;
172   toolbar->orientation  = GTK_ORIENTATION_HORIZONTAL;
173   toolbar->style        = GTK_TOOLBAR_ICONS;
174   toolbar->space_size   = DEFAULT_SPACE_SIZE;
175   toolbar->tooltips     = gtk_tooltips_new ();
176   toolbar->button_maxw  = 0;
177   toolbar->button_maxh  = 0;
178 }
179
180 GtkWidget *
181 gtk_toolbar_new (GtkOrientation  orientation,
182                  GtkToolbarStyle style)
183 {
184   GtkToolbar *toolbar;
185
186   toolbar = gtk_type_new (gtk_toolbar_get_type ());
187
188   toolbar->orientation = orientation;
189   toolbar->style = style;
190
191   return GTK_WIDGET (toolbar);
192 }
193
194 static void
195 gtk_toolbar_destroy (GtkObject *object)
196 {
197   GtkToolbar *toolbar;
198   GList      *children;
199   Child      *child;
200
201   g_return_if_fail (object != NULL);
202   g_return_if_fail (GTK_IS_TOOLBAR (object));
203
204   toolbar = GTK_TOOLBAR (object);
205
206   gtk_tooltips_unref (toolbar->tooltips);
207
208   for (children = toolbar->children; children; children = children->next)
209     {
210       child = children->data;
211
212       if (child->type != CHILD_SPACE)
213         {
214           child->widget->parent = NULL;
215           gtk_object_unref (GTK_OBJECT (child->widget));
216           gtk_widget_destroy (child->widget);
217         }
218
219       g_free (child);
220     }
221
222   g_list_free (toolbar->children);
223
224   if (GTK_OBJECT_CLASS (parent_class)->destroy)
225     (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
226 }
227
228 static void
229 gtk_toolbar_map (GtkWidget *widget)
230 {
231   GtkToolbar *toolbar;
232   GList      *children;
233   Child      *child;
234
235   g_return_if_fail (widget != NULL);
236   g_return_if_fail (GTK_IS_TOOLBAR (widget));
237
238   toolbar = GTK_TOOLBAR (widget);
239   GTK_WIDGET_SET_FLAGS (toolbar, GTK_MAPPED);
240
241   for (children = toolbar->children; children; children = children->next)
242     {
243       child = children->data;
244
245       if ((child->type != CHILD_SPACE)
246           && GTK_WIDGET_VISIBLE (child->widget) && !GTK_WIDGET_MAPPED (child->widget))
247         gtk_widget_map (child->widget);
248     }
249 }
250
251 static void
252 gtk_toolbar_unmap (GtkWidget *widget)
253 {
254   GtkToolbar *toolbar;
255   GList      *children;
256   Child      *child;
257
258   g_return_if_fail (widget != NULL);
259   g_return_if_fail (GTK_IS_TOOLBAR (widget));
260
261   toolbar = GTK_TOOLBAR (widget);
262   GTK_WIDGET_UNSET_FLAGS (toolbar, GTK_MAPPED);
263
264   for (children = toolbar->children; children; children = children->next)
265     {
266       child = children->data;
267
268       if ((child->type != CHILD_SPACE)
269           && GTK_WIDGET_VISIBLE (child->widget) && GTK_WIDGET_MAPPED (child->widget))
270         gtk_widget_unmap (child->widget);
271     }
272 }
273
274 static void
275 gtk_toolbar_draw (GtkWidget    *widget,
276                   GdkRectangle *area)
277 {
278   GtkToolbar   *toolbar;
279   GList        *children;
280   Child        *child;
281   GdkRectangle  child_area;
282
283   g_return_if_fail (widget != NULL);
284   g_return_if_fail (GTK_IS_TOOLBAR (widget));
285
286   if (GTK_WIDGET_DRAWABLE (widget))
287     {
288       toolbar = GTK_TOOLBAR (widget);
289
290       for (children = toolbar->children; children; children = children->next)
291         {
292           child = children->data;
293
294           if ((child->type != CHILD_SPACE)
295               && gtk_widget_intersect (child->widget, area, &child_area))
296             gtk_widget_draw (child->widget, &child_area);
297         }
298     }
299 }
300
301 static gint
302 gtk_toolbar_expose (GtkWidget      *widget,
303                     GdkEventExpose *event)
304 {
305   GtkToolbar     *toolbar;
306   GList          *children;
307   Child          *child;
308   GdkEventExpose  child_event;
309
310   g_return_val_if_fail (widget != NULL, FALSE);
311   g_return_val_if_fail (GTK_IS_TOOLBAR (widget), FALSE);
312   g_return_val_if_fail (event != NULL, FALSE);
313
314   if (GTK_WIDGET_DRAWABLE (widget))
315     {
316       toolbar = GTK_TOOLBAR (widget);
317
318       child_event = *event;
319
320       for (children = toolbar->children; children; children = children->next)
321         {
322           child = children->data;
323
324           if ((child->type != CHILD_SPACE)
325               && GTK_WIDGET_NO_WINDOW (child->widget)
326               && gtk_widget_intersect (child->widget, &event->area, &child_event.area))
327             gtk_widget_event (child->widget, (GdkEvent *) &child_event);
328         }
329     }
330
331   return FALSE;
332 }
333
334 static void
335 gtk_toolbar_size_request (GtkWidget      *widget,
336                           GtkRequisition *requisition)
337 {
338   GtkToolbar *toolbar;
339   GList      *children;
340   Child      *child;
341   gint        nbuttons;
342   gint        button_maxw, button_maxh;
343   gint        widget_maxw, widget_maxh;
344
345   g_return_if_fail (widget != NULL);
346   g_return_if_fail (GTK_IS_TOOLBAR (widget));
347   g_return_if_fail (requisition != NULL);
348
349   toolbar = GTK_TOOLBAR (widget);
350
351   requisition->width = GTK_CONTAINER (toolbar)->border_width * 2;
352   requisition->height = GTK_CONTAINER (toolbar)->border_width * 2;
353   nbuttons = 0;
354   button_maxw = 0;
355   button_maxh = 0;
356   widget_maxw = 0;
357   widget_maxh = 0;
358
359   for (children = toolbar->children; children; children = children->next)
360     {
361       child = children->data;
362
363       switch (child->type)
364         {
365         case CHILD_SPACE:
366           if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
367             requisition->width += toolbar->space_size;
368           else
369             requisition->height += toolbar->space_size;
370
371           break;
372
373         case CHILD_BUTTON:
374           if (GTK_WIDGET_VISIBLE (child->widget))
375             {
376               gtk_widget_size_request (child->widget, &child->widget->requisition);
377
378               nbuttons++;
379               button_maxw = MAX (button_maxw, child->widget->requisition.width);
380               button_maxh = MAX (button_maxh, child->widget->requisition.height);
381             }
382
383           break;
384
385         case CHILD_WIDGET:
386           if (GTK_WIDGET_VISIBLE (child->widget))
387             {
388               gtk_widget_size_request (child->widget, &child->widget->requisition);
389
390               widget_maxw = MAX (widget_maxw, child->widget->requisition.width);
391               widget_maxh = MAX (widget_maxh, child->widget->requisition.height);
392
393               if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
394                 requisition->width += child->widget->requisition.width;
395               else
396                 requisition->height += child->widget->requisition.height;
397             }
398
399           break;
400
401         default:
402           g_assert_not_reached ();
403         }
404     }
405
406   if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
407     {
408       requisition->width += nbuttons * button_maxw;
409       requisition->height += MAX (button_maxh, widget_maxh);
410     }
411   else
412     {
413       requisition->width += MAX (button_maxw, widget_maxw);
414       requisition->height += nbuttons * button_maxh;
415     }
416
417   toolbar->button_maxw = button_maxw;
418   toolbar->button_maxh = button_maxh;
419 }
420
421 static void
422 gtk_toolbar_size_allocate (GtkWidget     *widget,
423                            GtkAllocation *allocation)
424 {
425   GtkToolbar     *toolbar;
426   GList          *children;
427   Child          *child;
428   GtkAllocation   alloc;
429   gint            border_width;
430
431   g_return_if_fail (widget != NULL);
432   g_return_if_fail (GTK_IS_TOOLBAR (widget));
433   g_return_if_fail (allocation != NULL);
434
435   toolbar = GTK_TOOLBAR (widget);
436   widget->allocation = *allocation;
437
438   border_width = GTK_CONTAINER (toolbar)->border_width;
439
440   if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
441     alloc.x = allocation->x + border_width;
442   else
443     alloc.y = allocation->y + border_width;
444
445   for (children = toolbar->children; children; children = children->next)
446     {
447       child = children->data;
448
449       switch (child->type)
450         {
451         case CHILD_SPACE:
452           if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
453             alloc.x += toolbar->space_size;
454           else
455             alloc.y += toolbar->space_size;
456
457           break;
458
459         case CHILD_BUTTON:
460           alloc.width = toolbar->button_maxw;
461           alloc.height = toolbar->button_maxh;
462
463           if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
464             alloc.y = allocation->y + (allocation->height - toolbar->button_maxh) / 2;
465           else
466             alloc.x = allocation->x + (allocation->width - toolbar->button_maxw) / 2;
467
468           gtk_widget_size_allocate (child->widget, &alloc);
469
470           if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
471             alloc.x += toolbar->button_maxw;
472           else
473             alloc.y += toolbar->button_maxh;
474
475           break;
476
477         case CHILD_WIDGET:
478           alloc.width = child->widget->requisition.width;
479           alloc.height = child->widget->requisition.height;
480
481           if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
482             alloc.y = allocation->y + (allocation->height - child->widget->requisition.height) / 2;
483           else
484             alloc.x = allocation->x + (allocation->width - child->widget->requisition.width) / 2;
485
486           gtk_widget_size_allocate (child->widget, &alloc);
487
488           if (toolbar->orientation == GTK_ORIENTATION_HORIZONTAL)
489             alloc.x += child->widget->requisition.width;
490           else
491             alloc.y += child->widget->requisition.height;
492
493           break;
494
495         default:
496           g_assert_not_reached ();
497         }
498     }
499 }
500
501 static void
502 gtk_toolbar_add (GtkContainer *container,
503                  GtkWidget    *widget)
504 {
505   g_return_if_fail (container != NULL);
506   g_return_if_fail (GTK_IS_TOOLBAR (container));
507   g_return_if_fail (widget != NULL);
508
509   gtk_toolbar_append_widget (GTK_TOOLBAR (container), NULL, widget);
510 }
511
512 static void
513 gtk_toolbar_remove (GtkContainer *container,
514                     GtkWidget    *widget)
515 {
516   GtkToolbar *toolbar;
517   GList      *children;
518   Child      *child;
519
520   g_return_if_fail (container != NULL);
521   g_return_if_fail (GTK_IS_TOOLBAR (container));
522   g_return_if_fail (widget != NULL);
523
524   toolbar = GTK_TOOLBAR (container);
525
526   for (children = toolbar->children; children; children = children->next)
527     {
528       child = children->data;
529
530       if ((child->type != CHILD_SPACE) && (child->widget == widget))
531         {
532           gtk_widget_unparent (widget);
533
534           toolbar->children = g_list_remove_link (toolbar->children, children);
535           g_free (child);
536           g_list_free (children);
537           toolbar->num_children--;
538
539           if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_VISIBLE (container))
540             gtk_widget_queue_resize (GTK_WIDGET (container));
541
542           break;
543         }
544     }
545 }
546
547 static void
548 gtk_toolbar_foreach (GtkContainer *container,
549                      GtkCallback   callback,
550                      gpointer      callback_data)
551 {
552   GtkToolbar *toolbar;
553   GList      *children;
554   Child      *child;
555
556   g_return_if_fail (container != NULL);
557   g_return_if_fail (GTK_IS_TOOLBAR (container));
558   g_return_if_fail (callback != NULL);
559
560   toolbar = GTK_TOOLBAR (container);
561
562   for (children = toolbar->children; children; children = children->next)
563     {
564       child = children->data;
565
566       if (child->type != CHILD_SPACE)
567         (*callback) (child->widget, callback_data);
568     }
569 }
570
571 GtkWidget *
572 gtk_toolbar_append_item (GtkToolbar    *toolbar,
573                          const char    *text,
574                          const char    *tooltip_text,
575                          GtkPixmap     *icon,
576                          GtkSignalFunc  callback,
577                          gpointer       user_data)
578 {
579   return gtk_toolbar_insert_item (toolbar, text, tooltip_text, icon,
580                                   callback, user_data, toolbar->num_children);
581 }
582
583 GtkWidget *
584 gtk_toolbar_prepend_item (GtkToolbar    *toolbar,
585                           const char    *text,
586                           const char    *tooltip_text,
587                           GtkPixmap     *icon,
588                           GtkSignalFunc  callback,
589                           gpointer       user_data)
590 {
591   return gtk_toolbar_insert_item (toolbar, text, tooltip_text, icon,
592                                   callback, user_data, 0);
593 }
594
595 GtkWidget *
596 gtk_toolbar_insert_item (GtkToolbar    *toolbar,
597                          const char    *text,
598                          const char    *tooltip_text,
599                          GtkPixmap     *icon,
600                          GtkSignalFunc  callback,
601                          gpointer       user_data,
602                          gint           position)
603 {
604   Child     *child;
605   GtkWidget *vbox;
606
607   g_return_val_if_fail (toolbar != NULL, NULL);
608   g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
609
610   child = g_new (Child, 1);
611
612   child->type = CHILD_BUTTON;
613   child->widget = gtk_button_new ();
614
615   if (callback)
616     gtk_signal_connect (GTK_OBJECT (child->widget), "clicked",
617                         callback, user_data);
618
619   if (tooltip_text)
620     gtk_tooltips_set_tips (toolbar->tooltips, child->widget, tooltip_text);
621
622   if (text)
623     child->label = gtk_label_new (text);
624   else
625     child->label = NULL;
626
627   if (icon)
628     child->icon = GTK_WIDGET (icon);
629   else
630     child->icon = NULL;
631
632   vbox = gtk_vbox_new (FALSE, 0);
633   gtk_container_add (GTK_CONTAINER (child->widget), vbox);
634   gtk_widget_show (vbox);
635
636   if (child->icon)
637     gtk_box_pack_start (GTK_BOX (vbox), child->icon, FALSE, FALSE, 0);
638
639   if (child->label)
640     gtk_box_pack_start (GTK_BOX (vbox), child->label, FALSE, FALSE, 0);
641
642   switch (toolbar->style)
643     {
644     case GTK_TOOLBAR_ICONS:
645       if (child->icon)
646         gtk_widget_show (child->icon);
647       break;
648
649     case GTK_TOOLBAR_TEXT:
650       if (child->label)
651         gtk_widget_show (child->label);
652       break;
653
654     case GTK_TOOLBAR_BOTH:
655       if (child->icon)
656         gtk_widget_show (child->icon);
657
658       if (child->label)
659         gtk_widget_show (child->label);
660
661       break;
662
663     default:
664       g_assert_not_reached ();
665     }
666
667   gtk_widget_show (child->widget);
668
669   toolbar->children = g_list_insert (toolbar->children, child, position);
670   toolbar->num_children++;
671
672   gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar));
673
674   if (GTK_WIDGET_VISIBLE (toolbar))
675     {
676       if (GTK_WIDGET_REALIZED (toolbar)
677           && !GTK_WIDGET_REALIZED (child->widget))
678         gtk_widget_realize (child->widget);
679
680       if (GTK_WIDGET_MAPPED (toolbar)
681           && !GTK_WIDGET_MAPPED (child->widget))
682         gtk_widget_map (child->widget);
683     }
684
685   if (GTK_WIDGET_VISIBLE (child->widget) && GTK_WIDGET_VISIBLE (toolbar))
686     gtk_widget_queue_resize (child->widget);
687
688   return child->widget;
689 }
690
691 void
692 gtk_toolbar_append_space (GtkToolbar *toolbar)
693 {
694   gtk_toolbar_insert_space (toolbar, toolbar->num_children);
695 }
696
697 void
698 gtk_toolbar_prepend_space (GtkToolbar *toolbar)
699 {
700   gtk_toolbar_insert_space (toolbar, 0);
701 }
702
703 void
704 gtk_toolbar_insert_space (GtkToolbar *toolbar,
705                           gint        position)
706 {
707   Child *child;
708
709   g_return_if_fail (toolbar != NULL);
710   g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
711
712   child = g_new (Child, 1);
713   child->type   = CHILD_SPACE;
714   child->widget = NULL;
715   child->icon   = NULL;
716   child->label  = NULL;
717
718   toolbar->children = g_list_insert (toolbar->children, child, position);
719   toolbar->num_children++;
720
721   if (GTK_WIDGET_VISIBLE (toolbar))
722     gtk_widget_queue_resize (GTK_WIDGET (toolbar));
723 }
724
725 void
726 gtk_toolbar_append_widget (GtkToolbar *toolbar,
727                            const char *tooltip_text,
728                            GtkWidget  *widget)
729 {
730   gtk_toolbar_insert_widget (toolbar, tooltip_text, widget, toolbar->num_children);
731 }
732
733 void
734 gtk_toolbar_prepend_widget (GtkToolbar *toolbar,
735                             const char *tooltip_text,
736                             GtkWidget  *widget)
737 {
738   gtk_toolbar_insert_widget (toolbar, tooltip_text, widget, 0);
739 }
740
741 void
742 gtk_toolbar_insert_widget (GtkToolbar *toolbar,
743                            const char *tooltip_text,
744                            GtkWidget  *widget,
745                            gint        position)
746 {
747   Child *child;
748
749   g_return_if_fail (toolbar != NULL);
750   g_return_if_fail (widget != NULL);
751
752   child = g_new (Child, 1);
753   child->type   = CHILD_WIDGET;
754   child->widget = widget;
755   child->icon   = NULL;
756   child->label  = NULL;
757
758   if (tooltip_text)
759     gtk_tooltips_set_tips (toolbar->tooltips, child->widget, tooltip_text);
760
761   toolbar->children = g_list_insert (toolbar->children, child, position);
762   toolbar->num_children++;
763
764   gtk_widget_set_parent (child->widget, GTK_WIDGET (toolbar));
765
766   if (GTK_WIDGET_VISIBLE (toolbar))
767     {
768       if (GTK_WIDGET_REALIZED (toolbar)
769           && !GTK_WIDGET_REALIZED (child->widget))
770         gtk_widget_realize (child->widget);
771
772       if (GTK_WIDGET_MAPPED (toolbar)
773           && !GTK_WIDGET_MAPPED (child->widget))
774         gtk_widget_map (child->widget);
775     }
776
777   if (GTK_WIDGET_VISIBLE (child->widget) && GTK_WIDGET_VISIBLE (toolbar))
778     gtk_widget_queue_resize (child->widget);
779 }
780
781 void
782 gtk_toolbar_set_orientation (GtkToolbar     *toolbar,
783                              GtkOrientation  orientation)
784 {
785   gtk_signal_emit (GTK_OBJECT (toolbar), toolbar_signals[ORIENTATION_CHANGED], orientation);
786 }
787
788 void
789 gtk_toolbar_set_style (GtkToolbar      *toolbar,
790                        GtkToolbarStyle  style)
791 {
792   gtk_signal_emit (GTK_OBJECT (toolbar), toolbar_signals[STYLE_CHANGED], style);
793 }
794
795 void
796 gtk_toolbar_set_space_size (GtkToolbar *toolbar,
797                             gint        space_size)
798 {
799   g_return_if_fail (toolbar != NULL);
800   g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
801
802   if (toolbar->space_size != space_size)
803     {
804       toolbar->space_size = space_size;
805       gtk_widget_queue_resize (GTK_WIDGET (toolbar));
806     }
807 }
808
809 void
810 gtk_toolbar_set_tooltips (GtkToolbar *toolbar,
811                           gint        enable)
812 {
813   g_return_if_fail (toolbar != NULL);
814   g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
815
816   if (enable)
817     gtk_tooltips_enable (toolbar->tooltips);
818   else
819     gtk_tooltips_disable (toolbar->tooltips);
820 }
821
822 static void
823 gtk_toolbar_marshal_signal_1 (GtkObject     *object,
824                               GtkSignalFunc  func,
825                               gpointer       func_data,
826                               GtkArg        *args)
827 {
828   GtkToolbarSignal1 rfunc;
829
830   rfunc = (GtkToolbarSignal1) func;
831
832   (*rfunc) (object, GTK_VALUE_ENUM (args[0]), func_data);
833 }
834
835 static void
836 gtk_real_toolbar_orientation_changed (GtkToolbar     *toolbar,
837                                       GtkOrientation  orientation)
838 {
839   g_return_if_fail (toolbar != NULL);
840   g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
841
842   if (toolbar->orientation != orientation)
843     {
844       toolbar->orientation = orientation;
845       gtk_widget_queue_resize (GTK_WIDGET (toolbar));
846     }
847 }
848
849 static void
850 gtk_real_toolbar_style_changed (GtkToolbar      *toolbar,
851                                 GtkToolbarStyle  style)
852 {
853   GList *children;
854   Child *child;
855
856   g_return_if_fail (toolbar != NULL);
857   g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
858
859   if (toolbar->style != style)
860     {
861       toolbar->style = style;
862
863       for (children = toolbar->children; children; children = children->next)
864         {
865           child = children->data;
866
867           if (child->type == CHILD_BUTTON)
868             switch (style)
869               {
870               case GTK_TOOLBAR_ICONS:
871                 if (child->icon && !GTK_WIDGET_VISIBLE (child->icon))
872                   gtk_widget_show (child->icon);
873
874                 if (child->label && GTK_WIDGET_VISIBLE (child->label))
875                   gtk_widget_hide (child->label);
876
877                 break;
878
879               case GTK_TOOLBAR_TEXT:
880                 if (child->icon && GTK_WIDGET_VISIBLE (child->icon))
881                   gtk_widget_hide (child->icon);
882
883                 if (child->label && !GTK_WIDGET_VISIBLE (child->label))
884                   gtk_widget_show (child->label);
885
886                 break;
887
888               case GTK_TOOLBAR_BOTH:
889                 if (child->icon && !GTK_WIDGET_VISIBLE (child->icon))
890                   gtk_widget_show (child->icon);
891
892                 if (child->label && !GTK_WIDGET_VISIBLE (child->label))
893                   gtk_widget_show (child->label);
894
895                 break;
896
897               default:
898                 g_assert_not_reached ();
899               }
900         }
901                 
902       gtk_widget_queue_resize (GTK_WIDGET (toolbar));
903     }
904 }