]> Pileus Git - ~andy/gtk/blob - tests/testtoolbar.c
Add some more tests for menu placement.
[~andy/gtk] / tests / testtoolbar.c
1 /* testtoolbar.c
2  *
3  * Copyright (C) 2002 Anders Carlsson <andersca@codefactory.se>
4  * Copyright (C) 2002 James Henstridge <james@daa.com.au>
5  * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 #undef GTK_DISABLE_DEPRECATED
23 #include <config.h>
24 #include <gtk/gtk.h>
25 #include "prop-editor.h"
26
27 static void
28 reload_clicked (GtkWidget *widget)
29 {
30   static GdkAtom atom_rcfiles = GDK_NONE;
31
32   GdkEventClient sev;
33   int i;
34   
35   if (!atom_rcfiles)
36     atom_rcfiles = gdk_atom_intern("_GTK_READ_RCFILES", FALSE);
37
38   for(i = 0; i < 5; i++)
39     sev.data.l[i] = 0;
40   sev.data_format = 32;
41   sev.message_type = atom_rcfiles;
42   gdk_event_send_clientmessage_toall ((GdkEvent *) &sev);
43 }
44
45 static void
46 change_orientation (GtkWidget *button, GtkWidget *toolbar)
47 {
48   GtkWidget *table;
49   GtkOrientation orientation;
50
51   table = gtk_widget_get_parent (toolbar);
52   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
53     orientation = GTK_ORIENTATION_VERTICAL;
54   else
55     orientation = GTK_ORIENTATION_HORIZONTAL;
56
57   g_object_ref (toolbar);
58   gtk_container_remove (GTK_CONTAINER (table), toolbar);
59   gtk_toolbar_set_orientation (GTK_TOOLBAR (toolbar), orientation);
60   if (orientation == GTK_ORIENTATION_HORIZONTAL)
61     {
62       gtk_table_attach (GTK_TABLE (table), toolbar,
63                         0,2, 0,1, GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
64     }
65   else
66     {
67       gtk_table_attach (GTK_TABLE (table), toolbar,
68                         0,1, 0,4, GTK_FILL, GTK_FILL|GTK_EXPAND, 0, 0);
69     }
70   g_object_unref (toolbar);
71 }
72
73 static void
74 change_show_arrow (GtkWidget *button, GtkWidget *toolbar)
75 {
76   gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar),
77                 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)));
78 }
79
80 static void
81 set_toolbar_style_toggled (GtkCheckButton *button, GtkToolbar *toolbar)
82 {
83   GtkWidget *option_menu;
84   int style;
85   
86   option_menu = g_object_get_data (G_OBJECT (button), "option-menu");
87
88   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
89     {
90       style = gtk_option_menu_get_history (GTK_OPTION_MENU (option_menu));
91
92       gtk_toolbar_set_style (toolbar, style);
93       gtk_widget_set_sensitive (option_menu, TRUE);
94     }
95   else
96     {
97       gtk_toolbar_unset_style (toolbar);
98       gtk_widget_set_sensitive (option_menu, FALSE);
99     }
100 }
101
102 static void
103 change_toolbar_style (GtkWidget *option_menu, GtkWidget *toolbar)
104 {
105   GtkToolbarStyle style;
106
107   style = gtk_option_menu_get_history (GTK_OPTION_MENU (option_menu));
108   gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style);
109 }
110
111 static void
112 set_visible_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
113                  GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
114 {
115   GtkToolItem *tool_item;
116   gboolean visible;
117
118   gtk_tree_model_get (model, iter, 0, &tool_item, -1);
119
120   g_object_get (tool_item, "visible", &visible, NULL);
121   g_object_set (cell, "active", visible, NULL);
122   g_object_unref (tool_item);
123 }
124
125 static void
126 visibile_toggled(GtkCellRendererToggle *cell, const gchar *path_str,
127                  GtkTreeModel *model)
128 {
129   GtkTreePath *path;
130   GtkTreeIter iter;
131   GtkToolItem *tool_item;
132   gboolean visible;
133
134   path = gtk_tree_path_new_from_string (path_str);
135   gtk_tree_model_get_iter (model, &iter, path);
136
137   gtk_tree_model_get (model, &iter, 0, &tool_item, -1);
138   g_object_get (tool_item, "visible", &visible, NULL);
139   g_object_set (tool_item, "visible", !visible, NULL);
140   g_object_unref (tool_item);
141
142   gtk_tree_model_row_changed (model, path, &iter);
143   gtk_tree_path_free (path);
144 }
145
146 static void
147 set_expand_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
148                 GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
149 {
150   GtkToolItem *tool_item;
151
152   gtk_tree_model_get (model, iter, 0, &tool_item, -1);
153
154   g_object_set (cell, "active", gtk_tool_item_get_expand (tool_item), NULL);
155   g_object_unref (tool_item);
156 }
157
158 static void
159 expand_toggled(GtkCellRendererToggle *cell, const gchar *path_str,
160                GtkTreeModel *model)
161 {
162   GtkTreePath *path;
163   GtkTreeIter iter;
164   GtkToolItem *tool_item;
165
166   path = gtk_tree_path_new_from_string (path_str);
167   gtk_tree_model_get_iter (model, &iter, path);
168
169   gtk_tree_model_get (model, &iter, 0, &tool_item, -1);
170   gtk_tool_item_set_expand (tool_item, !gtk_tool_item_get_expand (tool_item));
171   g_object_unref (tool_item);
172
173   gtk_tree_model_row_changed (model, path, &iter);
174   gtk_tree_path_free (path);
175 }
176
177 static void
178 set_homogeneous_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
179                      GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
180 {
181   GtkToolItem *tool_item;
182
183   gtk_tree_model_get (model, iter, 0, &tool_item, -1);
184
185   g_object_set (cell, "active", gtk_tool_item_get_homogeneous (tool_item), NULL);
186   g_object_unref (tool_item);
187 }
188
189 static void
190 homogeneous_toggled(GtkCellRendererToggle *cell, const gchar *path_str,
191                     GtkTreeModel *model)
192 {
193   GtkTreePath *path;
194   GtkTreeIter iter;
195   GtkToolItem *tool_item;
196
197   path = gtk_tree_path_new_from_string (path_str);
198   gtk_tree_model_get_iter (model, &iter, path);
199
200   gtk_tree_model_get (model, &iter, 0, &tool_item, -1);
201   gtk_tool_item_set_homogeneous (tool_item, !gtk_tool_item_get_homogeneous (tool_item));
202   g_object_unref (tool_item);
203
204   gtk_tree_model_row_changed (model, path, &iter);
205   gtk_tree_path_free (path);
206 }
207
208
209 static void
210 set_important_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
211                    GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
212 {
213   GtkToolItem *tool_item;
214
215   gtk_tree_model_get (model, iter, 0, &tool_item, -1);
216
217   g_object_set (cell, "active", gtk_tool_item_get_is_important (tool_item), NULL);
218   g_object_unref (tool_item);
219 }
220
221 static void
222 important_toggled(GtkCellRendererToggle *cell, const gchar *path_str,
223                   GtkTreeModel *model)
224 {
225   GtkTreePath *path;
226   GtkTreeIter iter;
227   GtkToolItem *tool_item;
228
229   path = gtk_tree_path_new_from_string (path_str);
230   gtk_tree_model_get_iter (model, &iter, path);
231
232   gtk_tree_model_get (model, &iter, 0, &tool_item, -1);
233   gtk_tool_item_set_is_important (tool_item, !gtk_tool_item_get_is_important (tool_item));
234   g_object_unref (tool_item);
235
236   gtk_tree_model_row_changed (model, path, &iter);
237   gtk_tree_path_free (path);
238 }
239
240 static GtkListStore *
241 create_items_list (GtkWidget **tree_view_p)
242 {
243   GtkWidget *tree_view;
244   GtkListStore *list_store;
245   GtkCellRenderer *cell;
246   
247   list_store = gtk_list_store_new (2, GTK_TYPE_TOOL_ITEM, G_TYPE_STRING);
248   
249   tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
250
251   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
252                                                -1, "Tool Item",
253                                                gtk_cell_renderer_text_new (),
254                                                "text", 1, NULL);
255
256   cell = gtk_cell_renderer_toggle_new ();
257   g_signal_connect (cell, "toggled", G_CALLBACK (visibile_toggled),
258                     list_store);
259   gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
260                                               -1, "Visible",
261                                               cell,
262                                               set_visible_func, NULL, NULL);
263
264   cell = gtk_cell_renderer_toggle_new ();
265   g_signal_connect (cell, "toggled", G_CALLBACK (expand_toggled),
266                     list_store);
267   gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
268                                               -1, "Expand",
269                                               cell,
270                                               set_expand_func, NULL, NULL);
271
272   cell = gtk_cell_renderer_toggle_new ();
273   g_signal_connect (cell, "toggled", G_CALLBACK (homogeneous_toggled),
274                     list_store);
275   gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
276                                               -1, "Homogeneous",
277                                               cell,
278                                               set_homogeneous_func, NULL,NULL);
279
280   cell = gtk_cell_renderer_toggle_new ();
281   g_signal_connect (cell, "toggled", G_CALLBACK (important_toggled),
282                     list_store);
283   gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
284                                               -1, "Important",
285                                               cell,
286                                               set_important_func, NULL,NULL);
287
288   g_object_unref (list_store);
289
290   *tree_view_p = tree_view;
291
292   return list_store;
293 }
294
295 static void
296 add_item_to_list (GtkListStore *store, GtkToolItem *item, const gchar *text)
297 {
298   GtkTreeIter iter;
299
300   gtk_list_store_append (store, &iter);
301   gtk_list_store_set (store, &iter,
302                       0, item,
303                       1, text,
304                       -1);
305   
306 }
307
308 static void
309 bold_toggled (GtkToggleToolButton *button)
310 {
311   g_message ("Bold toggled (active=%d)",
312              gtk_toggle_tool_button_get_active (button));
313 }
314
315 static void
316 set_icon_size_toggled (GtkCheckButton *button, GtkToolbar *toolbar)
317 {
318   GtkWidget *option_menu;
319   int icon_size;
320   
321   option_menu = g_object_get_data (G_OBJECT (button), "option-menu");
322
323   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
324     {
325       icon_size = gtk_option_menu_get_history (GTK_OPTION_MENU (option_menu));
326       icon_size += GTK_ICON_SIZE_SMALL_TOOLBAR;
327
328       gtk_toolbar_set_icon_size (toolbar, icon_size);
329       gtk_widget_set_sensitive (option_menu, TRUE);
330     }
331   else
332     {
333       gtk_toolbar_unset_icon_size (toolbar);
334       gtk_widget_set_sensitive (option_menu, FALSE);
335     }
336 }
337
338 static void
339 icon_size_history_changed (GtkOptionMenu *menu, GtkToolbar *toolbar)
340 {
341   int icon_size;
342
343   icon_size = gtk_option_menu_get_history (menu);
344   icon_size += GTK_ICON_SIZE_SMALL_TOOLBAR;
345
346   gtk_toolbar_set_icon_size (toolbar, icon_size);
347 }
348
349 static gboolean
350 toolbar_drag_drop (GtkWidget *widget, GdkDragContext *context,
351                    gint x, gint y, guint time, GtkWidget *label)
352 {
353   gchar buf[32];
354
355   g_snprintf(buf, sizeof(buf), "%d",
356              gtk_toolbar_get_drop_index (GTK_TOOLBAR (widget), x, y));
357   gtk_label_set_label (GTK_LABEL (label), buf);
358
359   return TRUE;
360 }
361
362 static GtkTargetEntry target_table[] = {
363   { "application/x-toolbar-item", 0, 0 }
364 };
365
366 static GtkWidget *
367 make_prop_editor (GObject *object)
368 {
369   GtkWidget *prop_editor = create_prop_editor (object, 0);
370   gtk_widget_show (prop_editor);
371   return prop_editor;
372 }
373
374 static void
375 rtl_toggled (GtkCheckButton *check)
376 {
377   if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)))
378     gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
379   else
380     gtk_widget_set_default_direction (GTK_TEXT_DIR_LTR);
381 }
382
383 typedef struct
384 {
385   int x;
386   int y;
387 } MenuPositionData;
388
389 static void
390 position_function (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data)
391 {
392   /* Do not do this in your own code */
393
394   MenuPositionData *position_data = user_data;
395
396   if (x)
397     *x = position_data->x;
398
399   if (y)
400     *y = position_data->y;
401
402   if (push_in)
403     *push_in = FALSE;
404 }
405
406 static gboolean
407 popup_context_menu (GtkToolbar *toolbar, gint x, gint y, gint button_number)
408 {
409   MenuPositionData position_data;
410   
411   GtkMenu *menu = GTK_MENU (gtk_menu_new ());
412   int i;
413
414   for (i = 0; i < 5; i++)
415     {
416       GtkWidget *item;
417       gchar *label = g_strdup_printf ("Item _%d", i);
418       item = gtk_menu_item_new_with_mnemonic (label);
419       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
420     }
421   gtk_widget_show_all (GTK_WIDGET (menu));
422
423   if (button_number != -1)
424     {
425       position_data.x = x;
426       position_data.y = y;
427       
428       gtk_menu_popup (menu, NULL, NULL, position_function,
429                       &position_data, button_number, gtk_get_current_event_time());
430     }
431   else
432     gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time());
433
434   return TRUE;
435 }
436
437 static GtkToolItem *drag_item = NULL;
438
439 static gboolean
440 toolbar_drag_motion (GtkToolbar     *toolbar,
441                      GdkDragContext *context,
442                      gint            x,
443                      gint            y,
444                      guint           time,
445                      gpointer        null)
446 {
447   gint index;
448   
449   if (!drag_item)
450     {
451       drag_item = gtk_tool_button_new (NULL, "A quite long button");
452       gtk_object_sink (GTK_OBJECT (g_object_ref (drag_item)));
453     }
454   
455   gdk_drag_status (context, GDK_ACTION_MOVE, time);
456
457   index = gtk_toolbar_get_drop_index (toolbar, x, y);
458   
459   gtk_toolbar_set_drop_highlight_item (toolbar, drag_item, index);
460   
461   return TRUE;
462 }
463
464 static void
465 toolbar_drag_leave (GtkToolbar     *toolbar,
466                     GdkDragContext *context,
467                     guint           time,
468                     gpointer        null)
469 {
470   if (drag_item)
471     {
472       g_object_unref (drag_item);
473       drag_item = NULL;
474     }
475   
476   gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
477 }
478
479 static gboolean
480 timeout_cb (GtkWidget *widget)
481 {
482   static gboolean sensitive = TRUE;
483   
484   sensitive = !sensitive;
485   
486   gtk_widget_set_sensitive (widget, sensitive);
487   
488   return TRUE;
489 }
490
491 static gboolean
492 timeout_cb1 (GtkWidget *widget)
493 {
494         static gboolean sensitive = TRUE;
495         sensitive = !sensitive;
496         gtk_widget_set_sensitive (widget, sensitive);
497         return TRUE;
498 }
499
500 gint
501 main (gint argc, gchar **argv)
502 {
503   GtkWidget *window, *toolbar, *table, *treeview, *scrolled_window;
504   GtkWidget *hbox, *hbox1, *hbox2, *checkbox, *option_menu, *menu;
505   gint i;
506   static const gchar *toolbar_styles[] = { "icons", "text", "both (vertical)",
507                                            "both (horizontal)" };
508   GtkToolItem *item;
509   GtkListStore *store;
510   GtkWidget *image;
511   GtkWidget *menuitem;
512   GtkWidget *button;
513   GtkWidget *label;
514   GSList *group;
515   
516   gtk_init (&argc, &argv);
517
518   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
519
520   g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
521
522   table = gtk_table_new (4, 2, FALSE);
523   gtk_container_add (GTK_CONTAINER (window), table);
524
525   toolbar = gtk_toolbar_new ();
526   gtk_table_attach (GTK_TABLE (table), toolbar,
527                     0,2, 0,1, GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
528
529   hbox1 = gtk_hbox_new (FALSE, 3);
530   gtk_container_set_border_width (GTK_CONTAINER (hbox1), 5);
531   gtk_table_attach (GTK_TABLE (table), hbox1,
532                     1,2, 1,2, GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
533
534   hbox2 = gtk_hbox_new (FALSE, 2);
535   gtk_container_set_border_width (GTK_CONTAINER (hbox2), 5);
536   gtk_table_attach (GTK_TABLE (table), hbox2,
537                     1,2, 2,3, GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
538
539   checkbox = gtk_check_button_new_with_mnemonic("_Vertical");
540   gtk_box_pack_start (GTK_BOX (hbox1), checkbox, FALSE, FALSE, 0);
541   g_signal_connect (checkbox, "toggled",
542                     G_CALLBACK (change_orientation), toolbar);
543
544   checkbox = gtk_check_button_new_with_mnemonic("_Show Arrow");
545   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE);
546   gtk_box_pack_start (GTK_BOX (hbox1), checkbox, FALSE, FALSE, 0);
547   g_signal_connect (checkbox, "toggled",
548                     G_CALLBACK (change_show_arrow), toolbar);
549
550   checkbox = gtk_check_button_new_with_mnemonic("_Set Toolbar Style:");
551   g_signal_connect (checkbox, "toggled", G_CALLBACK (set_toolbar_style_toggled), toolbar);
552   gtk_box_pack_start (GTK_BOX (hbox1), checkbox, FALSE, FALSE, 0);
553   
554   option_menu = gtk_option_menu_new();
555   gtk_widget_set_sensitive (option_menu, FALSE);  
556   g_object_set_data (G_OBJECT (checkbox), "option-menu", option_menu);
557   
558   menu = gtk_menu_new();
559   for (i = 0; i < G_N_ELEMENTS (toolbar_styles); i++)
560     {
561       GtkWidget *menuitem;
562
563       menuitem = gtk_menu_item_new_with_label (toolbar_styles[i]);
564       gtk_container_add (GTK_CONTAINER (menu), menuitem);
565       gtk_widget_show (menuitem);
566     }
567   gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
568   gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu),
569                                GTK_TOOLBAR (toolbar)->style);
570   gtk_box_pack_start (GTK_BOX (hbox2), option_menu, FALSE, FALSE, 0);
571   g_signal_connect (option_menu, "changed",
572                     G_CALLBACK (change_toolbar_style), toolbar);
573
574   checkbox = gtk_check_button_new_with_mnemonic("_Set Icon Size:"); 
575   g_signal_connect (checkbox, "toggled", G_CALLBACK (set_icon_size_toggled), toolbar);
576   gtk_box_pack_start (GTK_BOX (hbox2), checkbox, FALSE, FALSE, 0);
577
578   option_menu = gtk_option_menu_new();
579   g_object_set_data (G_OBJECT (checkbox), "option-menu", option_menu);
580   gtk_widget_set_sensitive (option_menu, FALSE);
581   menu = gtk_menu_new();
582   menuitem = gtk_menu_item_new_with_label ("small toolbar");
583   g_object_set_data (G_OBJECT (menuitem), "value-id", GINT_TO_POINTER (GTK_ICON_SIZE_SMALL_TOOLBAR));
584   gtk_container_add (GTK_CONTAINER (menu), menuitem);
585   gtk_widget_show (menuitem);
586
587   menuitem = gtk_menu_item_new_with_label ("large toolbar");
588   g_object_set_data (G_OBJECT (menuitem), "value-id", GINT_TO_POINTER (GTK_ICON_SIZE_LARGE_TOOLBAR));
589   gtk_container_add (GTK_CONTAINER (menu), menuitem);
590   gtk_widget_show (menuitem);
591
592   gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
593   gtk_box_pack_start (GTK_BOX (hbox2), option_menu, FALSE, FALSE, 0);
594   g_signal_connect (option_menu, "changed",
595                     G_CALLBACK (icon_size_history_changed), toolbar);
596   
597   scrolled_window = gtk_scrolled_window_new (NULL, NULL);
598   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
599                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
600   gtk_table_attach (GTK_TABLE (table), scrolled_window,
601                     1,2, 3,4, GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0);
602
603   store = create_items_list (&treeview);
604   gtk_container_add (GTK_CONTAINER (scrolled_window), treeview);
605   
606   item = gtk_tool_button_new_from_stock (GTK_STOCK_NEW);
607   gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Custom label");
608   gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), NULL);
609   add_item_to_list (store, item, "New");
610   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
611   g_timeout_add (3000, (GSourceFunc) timeout_cb, item);
612   gtk_tool_item_set_expand (item, TRUE);
613
614   menu = gtk_menu_new ();
615   for (i = 0; i < 20; i++)
616     {
617       char *text;
618       text = g_strdup_printf ("Menuitem %d", i);
619       menuitem = gtk_menu_item_new_with_label (text);
620       g_free (text);
621       gtk_widget_show (menuitem);
622       gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
623     }
624
625   item = gtk_menu_tool_button_new_from_stock (GTK_STOCK_OPEN);
626   gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu);
627   add_item_to_list (store, item, "Open");
628   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
629   g_timeout_add (3000, (GSourceFunc) timeout_cb1, item);
630  
631   menu = gtk_menu_new ();
632   for (i = 0; i < 20; i++)
633     {
634       char *text;
635       text = g_strdup_printf ("A%d", i);
636       menuitem = gtk_menu_item_new_with_label (text);
637       g_free (text);
638       gtk_widget_show (menuitem);
639       gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
640     }
641
642   item = gtk_menu_tool_button_new_from_stock (GTK_STOCK_GO_BACK);
643   gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu);
644   add_item_to_list (store, item, "BackWithHistory");
645   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
646  
647   item = gtk_separator_tool_item_new ();
648   add_item_to_list (store, item, "-----");    
649   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
650   
651   item = gtk_tool_button_new_from_stock (GTK_STOCK_REFRESH);
652   add_item_to_list (store, item, "Refresh");
653   g_signal_connect (item, "clicked", G_CALLBACK (reload_clicked), NULL);
654   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
655
656   image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
657   item = gtk_tool_item_new ();
658   gtk_widget_show (image);
659   gtk_container_add (GTK_CONTAINER (item), image);
660   add_item_to_list (store, item, "(Custom Item)");    
661   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
662   
663   item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_BACK);
664   add_item_to_list (store, item, "Back");    
665   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
666
667   item = gtk_separator_tool_item_new ();
668   add_item_to_list (store, item, "-----");  
669   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
670   
671   item = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD);
672   add_item_to_list (store, item, "Forward");  
673   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
674
675   item = gtk_toggle_tool_button_new_from_stock (GTK_STOCK_BOLD);
676   g_signal_connect (item, "toggled", G_CALLBACK (bold_toggled), NULL);
677   add_item_to_list (store, item, "Bold");  
678   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
679   gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
680
681   item = gtk_separator_tool_item_new ();
682   add_item_to_list (store, item, "-----");  
683   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
684   gtk_tool_item_set_expand (item, TRUE);
685   gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (item), FALSE);
686   g_assert (gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), 0) != 0);
687   
688   item = gtk_radio_tool_button_new_from_stock (NULL, GTK_STOCK_JUSTIFY_LEFT);
689   group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item));
690   add_item_to_list (store, item, "Left");
691   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
692   
693   
694   item = gtk_radio_tool_button_new_from_stock (group, GTK_STOCK_JUSTIFY_CENTER);
695   make_prop_editor (G_OBJECT (item));
696
697   group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item));
698   add_item_to_list (store, item, "Center");
699   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
700
701   item = gtk_radio_tool_button_new_from_stock (group, GTK_STOCK_JUSTIFY_RIGHT);
702   add_item_to_list (store, item, "Right");
703   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
704
705   item = gtk_tool_button_new (gtk_image_new_from_file ("apple-red.png"), "_Apple");
706   add_item_to_list (store, item, "Apple");
707   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
708   gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (item), TRUE);
709   
710   hbox = gtk_hbox_new (FALSE, 5);
711   gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
712   gtk_table_attach (GTK_TABLE (table), hbox,
713                     1,2, 4,5, GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
714
715   button = gtk_button_new_with_label ("Drag me to the toolbar");
716   gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
717
718   label = gtk_label_new ("Drop index:");
719   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
720
721   label = gtk_label_new ("");
722   gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
723
724   checkbox = gtk_check_button_new_with_mnemonic("_Right to left");
725   if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL)
726     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE);
727   else
728     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), FALSE);
729   g_signal_connect (checkbox, "toggled", G_CALLBACK (rtl_toggled), NULL);
730
731   gtk_box_pack_end (GTK_BOX (hbox), checkbox, FALSE, FALSE, 0);
732   
733   gtk_drag_source_set (button, GDK_BUTTON1_MASK,
734                        target_table, G_N_ELEMENTS (target_table),
735                        GDK_ACTION_MOVE);
736   gtk_drag_dest_set (toolbar, GTK_DEST_DEFAULT_DROP,
737                      target_table, G_N_ELEMENTS (target_table),
738                      GDK_ACTION_MOVE);
739   g_signal_connect (toolbar, "drag_motion",
740                     G_CALLBACK (toolbar_drag_motion), NULL);
741   g_signal_connect (toolbar, "drag_leave",
742                     G_CALLBACK (toolbar_drag_leave), NULL);
743   g_signal_connect (toolbar, "drag_drop",
744                     G_CALLBACK (toolbar_drag_drop), label);
745
746   gtk_widget_show_all (window);
747
748   make_prop_editor (G_OBJECT (toolbar));
749
750   g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
751   
752   g_signal_connect (toolbar, "popup_context_menu", G_CALLBACK (popup_context_menu), NULL);
753   
754   gtk_main ();
755   
756   return 0;
757 }