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