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