2 * Copyright (C) 2003, 2004 Marco Pesenti Gritti
3 * Copyright (C) 2003, 2004, 2005 Christian Persch
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "egg-editable-toolbar.h"
25 #include "egg-toolbars-model.h"
26 #include "egg-toolbar-editor.h"
28 #include <gtk/gtkvseparator.h>
29 #include <gtk/gtkiconfactory.h>
30 #include <gtk/gtkwindow.h>
31 #include <gtk/gtkmain.h>
32 #include <gtk/gtkdnd.h>
33 #include <gtk/gtkhbox.h>
34 #include <gtk/gtkimage.h>
35 #include <gtk/gtktoggleaction.h>
36 #include <gtk/gtkcheckmenuitem.h>
37 #include <gtk/gtkimagemenuitem.h>
38 #include <gtk/gtkseparatormenuitem.h>
39 #include <gtk/gtkmenu.h>
40 #include <gtk/gtkstock.h>
41 #include <gtk/gtklabel.h>
42 #include <gtk/gtkbutton.h>
43 #include <gtk/gtktoolbar.h>
44 #include <gtk/gtktoolitem.h>
45 #include <gtk/gtktoolbutton.h>
46 #include <gtk/gtkseparatortoolitem.h>
47 #include <gtk/gtkicontheme.h>
48 #include <glib/gi18n.h>
51 static void egg_editable_toolbar_class_init (EggEditableToolbarClass *klass);
52 static void egg_editable_toolbar_init (EggEditableToolbar *etoolbar);
53 static GdkPixbuf * new_separator_pixbuf (void);
55 #define MIN_TOOLBAR_HEIGHT 20
56 #define EGG_ITEM_NAME "egg-item-name"
57 #define STOCK_DRAG_MODE "stock_drag-mode"
59 static const GtkTargetEntry dest_drag_types[] = {
60 {EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0},
79 static guint egg_editable_toolbar_signals[LAST_SIGNAL] = { 0 };
81 static GObjectClass *parent_class = NULL;
83 #define EGG_EDITABLE_TOOLBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EGG_TYPE_EDITABLE_TOOLBAR, EggEditableToolbarPrivate))
85 struct _EggEditableToolbarPrivate
87 GtkUIManager *manager;
88 EggToolbarsModel *model;
91 GtkWidget *fixed_toolbar;
94 GtkActionGroup *actions;
97 GList *visibility_paths;
98 GPtrArray *visibility_actions;
103 GtkToolbar *dnd_toolbar;
104 GtkToolItem *dnd_toolitem;
108 egg_editable_toolbar_get_type (void)
110 static GType type = 0;
112 if (G_UNLIKELY (type == 0))
114 static const GTypeInfo our_info = {
115 sizeof (EggEditableToolbarClass),
116 NULL, /* base_init */
117 NULL, /* base_finalize */
118 (GClassInitFunc) egg_editable_toolbar_class_init,
120 NULL, /* class_data */
121 sizeof (EggEditableToolbar),
123 (GInstanceInitFunc) egg_editable_toolbar_init
126 type = g_type_register_static (GTK_TYPE_VBOX,
127 "EggEditableToolbar",
135 get_dock_position (EggEditableToolbar *etoolbar,
141 l = gtk_container_get_children (GTK_CONTAINER (etoolbar));
142 result = g_list_index (l, dock);
149 get_toolbar_position (EggEditableToolbar *etoolbar, GtkWidget *toolbar)
151 return get_dock_position (etoolbar, toolbar->parent);
155 get_n_toolbars (EggEditableToolbar *etoolbar)
160 l = gtk_container_get_children (GTK_CONTAINER (etoolbar));
161 result = g_list_length (l);
168 get_dock_nth (EggEditableToolbar *etoolbar,
174 l = gtk_container_get_children (GTK_CONTAINER (etoolbar));
175 result = g_list_nth_data (l, position);
182 get_toolbar_nth (EggEditableToolbar *etoolbar,
189 dock = get_dock_nth (etoolbar, position);
190 g_return_val_if_fail (dock != NULL, NULL);
192 l = gtk_container_get_children (GTK_CONTAINER (dock));
193 result = GTK_WIDGET (l->data);
200 find_action (EggEditableToolbar *etoolbar,
204 GtkAction *action = NULL;
206 l = gtk_ui_manager_get_action_groups (etoolbar->priv->manager);
208 g_return_val_if_fail (name != NULL, NULL);
210 for (; l != NULL; l = l->next)
214 tmp = gtk_action_group_get_action (GTK_ACTION_GROUP (l->data), name);
223 drag_data_delete_cb (GtkWidget *widget,
224 GdkDragContext *context,
225 EggEditableToolbar *etoolbar)
227 int pos, toolbar_pos;
229 widget = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
230 g_return_if_fail (widget != NULL);
231 g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
233 pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (widget->parent),
234 GTK_TOOL_ITEM (widget));
235 toolbar_pos = get_toolbar_position (etoolbar, widget->parent);
237 egg_toolbars_model_remove_item (etoolbar->priv->model,
242 drag_begin_cb (GtkWidget *widget,
243 GdkDragContext *context,
244 EggEditableToolbar *etoolbar)
249 gtk_widget_hide (widget);
251 action = g_object_get_data (G_OBJECT (widget), "gtk-action");
252 if (action == NULL) return;
254 flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model,
255 gtk_action_get_name (action));
256 if (!(flags & EGG_TB_MODEL_NAME_INFINITE))
258 flags &= ~EGG_TB_MODEL_NAME_USED;
259 egg_toolbars_model_set_name_flags (etoolbar->priv->model,
260 gtk_action_get_name (action),
266 drag_end_cb (GtkWidget *widget,
267 GdkDragContext *context,
268 EggEditableToolbar *etoolbar)
273 if (gtk_widget_get_parent (widget) != NULL)
275 gtk_widget_show (widget);
277 action = g_object_get_data (G_OBJECT (widget), "gtk-action");
278 if (action == NULL) return;
280 flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model,
281 gtk_action_get_name (action));
282 if (!(flags & EGG_TB_MODEL_NAME_INFINITE))
284 flags |= EGG_TB_MODEL_NAME_USED;
285 egg_toolbars_model_set_name_flags (etoolbar->priv->model,
286 gtk_action_get_name (action),
293 drag_data_get_cb (GtkWidget *widget,
294 GdkDragContext *context,
295 GtkSelectionData *selection_data,
298 EggEditableToolbar *etoolbar)
300 EggToolbarsModel *model;
304 g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
305 model = egg_editable_toolbar_get_model (etoolbar);
307 name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
310 name = g_object_get_data (G_OBJECT (gtk_widget_get_parent (widget)), EGG_ITEM_NAME);
311 g_return_if_fail (name != NULL);
314 data = egg_toolbars_model_get_data (model, selection_data->target, name);
317 gtk_selection_data_set (selection_data, selection_data->target, 8, (unsigned char *)data, strlen (data));
323 move_item_cb (GtkAction *action,
324 EggEditableToolbar *etoolbar)
326 GtkWidget *toolitem = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM);
327 GtkTargetList *list = gtk_target_list_new (dest_drag_types, G_N_ELEMENTS (dest_drag_types));
329 GdkEvent *realevent = gtk_get_current_event();
330 GdkEventMotion event;
331 event.type = GDK_MOTION_NOTIFY;
332 event.window = realevent->any.window;
333 event.send_event = FALSE;
335 event.time = gdk_event_get_time (realevent);
336 gdk_event_get_state (realevent, &event.state);
337 gdk_event_get_coords (realevent, &event.x, &event.y);
338 gdk_event_get_root_coords (realevent, &event.x_root, &event.y_root);
340 gtk_drag_begin (toolitem, list, GDK_ACTION_MOVE, 1, (GdkEvent *)&event);
341 gtk_target_list_unref (list);
345 remove_item_cb (GtkAction *action,
346 EggEditableToolbar *etoolbar)
348 GtkWidget *toolitem = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM);
349 int pos, toolbar_pos;
351 toolbar_pos = get_toolbar_position (etoolbar, toolitem->parent);
352 pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolitem->parent),
353 GTK_TOOL_ITEM (toolitem));
355 egg_toolbars_model_remove_item (etoolbar->priv->model,
358 if (egg_toolbars_model_n_items (etoolbar->priv->model, toolbar_pos) == 0)
360 egg_toolbars_model_remove_toolbar (etoolbar->priv->model, toolbar_pos);
365 remove_toolbar_cb (GtkAction *action,
366 EggEditableToolbar *etoolbar)
368 GtkWidget *selected = egg_editable_toolbar_get_selected (etoolbar);
369 GtkWidget *toolbar = gtk_widget_get_ancestor (selected, GTK_TYPE_TOOLBAR);
372 toolbar_pos = get_toolbar_position (etoolbar, toolbar);
373 egg_toolbars_model_remove_toolbar (etoolbar->priv->model, toolbar_pos);
377 popup_context_deactivate (GtkMenuShell *menu,
378 EggEditableToolbar *etoolbar)
380 egg_editable_toolbar_set_selected (etoolbar, NULL);
381 g_object_notify (G_OBJECT (etoolbar), "selected");
385 popup_context_menu_cb (GtkWidget *toolbar,
389 EggEditableToolbar *etoolbar)
391 if (etoolbar->priv->popup_path != NULL)
395 egg_editable_toolbar_set_selected (etoolbar, toolbar);
396 g_object_notify (G_OBJECT (etoolbar), "selected");
398 menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
399 etoolbar->priv->popup_path));
400 g_return_if_fail (menu != NULL);
401 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, button_number, gtk_get_current_event_time ());
402 g_signal_connect_object (menu, "selection-done",
403 G_CALLBACK (popup_context_deactivate),
409 button_press_event_cb (GtkWidget *widget,
410 GdkEventButton *event,
411 EggEditableToolbar *etoolbar)
413 if (event->button == 3 && etoolbar->priv->popup_path != NULL)
417 egg_editable_toolbar_set_selected (etoolbar, widget);
418 g_object_notify (G_OBJECT (etoolbar), "selected");
420 menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
421 etoolbar->priv->popup_path));
422 g_return_val_if_fail (menu != NULL, FALSE);
423 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button, event->time);
424 g_signal_connect_object (menu, "selection-done",
425 G_CALLBACK (popup_context_deactivate),
435 configure_item_sensitivity (GtkToolItem *item, EggEditableToolbar *etoolbar)
440 name = g_object_get_data (G_OBJECT (item), EGG_ITEM_NAME);
441 action = name ? find_action (etoolbar, name) : NULL;
445 g_object_notify (G_OBJECT (action), "sensitive");
448 gtk_tool_item_set_use_drag_window (item,
449 (etoolbar->priv->edit_mode > 0) ||
450 GTK_IS_SEPARATOR_TOOL_ITEM (item));
455 configure_item_cursor (GtkToolItem *item,
456 EggEditableToolbar *etoolbar)
458 EggEditableToolbarPrivate *priv = etoolbar->priv;
459 GtkWidget *widget = GTK_WIDGET (item);
461 if (widget->window != NULL)
463 if (priv->edit_mode > 0)
466 GdkPixbuf *pixbuf = NULL;
468 cursor = gdk_cursor_new (GDK_HAND2);
469 gdk_window_set_cursor (widget->window, cursor);
470 gdk_cursor_unref (cursor);
472 gtk_drag_source_set (widget, GDK_BUTTON1_MASK, dest_drag_types,
473 G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE);
474 if (GTK_IS_SEPARATOR_TOOL_ITEM (item))
476 pixbuf = new_separator_pixbuf ();
480 char *icon_name=NULL;
485 name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
486 action = name ? find_action (etoolbar, name) : NULL;
490 g_object_get (action,
491 "icon-name", &icon_name,
492 "stock-id", &stock_id,
498 GtkIconTheme *icon_theme;
499 GtkSettings *settings;
502 screen = gtk_widget_get_screen (widget);
503 icon_theme = gtk_icon_theme_get_for_screen (screen);
504 settings = gtk_settings_get_for_screen (screen);
506 if (!gtk_icon_size_lookup_for_settings (settings,
507 GTK_ICON_SIZE_LARGE_TOOLBAR,
513 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
514 MIN (width, height), 0, NULL);
518 pixbuf = gtk_widget_render_icon (widget, stock_id,
519 GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
525 if (G_UNLIKELY (!pixbuf))
529 gtk_drag_source_set_icon_pixbuf (widget, pixbuf);
530 g_object_unref (pixbuf);
535 gdk_window_set_cursor (GTK_WIDGET(item)->window, NULL);
542 configure_item_tooltip (GtkToolItem *item)
544 GtkAction *action = g_object_get_data (G_OBJECT (item),
549 g_object_notify (G_OBJECT (action), "tooltip");
555 connect_widget_signals (GtkWidget *proxy, EggEditableToolbar *etoolbar)
557 if (GTK_IS_CONTAINER (proxy))
559 gtk_container_forall (GTK_CONTAINER (proxy),
560 (GtkCallback) connect_widget_signals,
561 (gpointer) etoolbar);
564 if (GTK_IS_TOOL_ITEM (proxy))
566 g_signal_connect_object (proxy, "drag_begin",
567 G_CALLBACK (drag_begin_cb),
569 g_signal_connect_object (proxy, "drag_end",
570 G_CALLBACK (drag_end_cb),
572 g_signal_connect_object (proxy, "drag_data_get",
573 G_CALLBACK (drag_data_get_cb),
575 g_signal_connect_object (proxy, "drag_data_delete",
576 G_CALLBACK (drag_data_delete_cb),
580 if (GTK_IS_BUTTON (proxy) || GTK_IS_TOOL_ITEM (proxy))
582 g_signal_connect_object (proxy, "button-press-event",
583 G_CALLBACK (button_press_event_cb),
589 action_sensitive_cb (GtkAction *action,
593 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR
594 (gtk_widget_get_ancestor (GTK_WIDGET (item), EGG_TYPE_EDITABLE_TOOLBAR));
596 if (etoolbar->priv->edit_mode > 0)
598 gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
603 create_item_from_action (EggEditableToolbar *etoolbar,
608 g_return_val_if_fail (name != NULL, NULL);
610 if (strcmp (name, "_separator") == 0)
612 item = gtk_separator_tool_item_new ();
616 GtkAction *action = find_action (etoolbar, name);
617 if (action == NULL) return NULL;
619 item = GTK_TOOL_ITEM (gtk_action_create_tool_item (action));
621 /* Normally done on-demand by the GtkUIManager, but no
622 * such demand may have been made yet, so do it ourselves.
624 gtk_action_set_accel_group
625 (action, gtk_ui_manager_get_accel_group(etoolbar->priv->manager));
627 g_signal_connect_object (action, "notify::sensitive",
628 G_CALLBACK (action_sensitive_cb), item, 0);
631 gtk_widget_show (GTK_WIDGET (item));
633 g_object_set_data_full (G_OBJECT (item), EGG_ITEM_NAME,
634 g_strdup (name), g_free);
640 create_item_from_position (EggEditableToolbar *etoolbar,
641 int toolbar_position,
647 name = egg_toolbars_model_item_nth (etoolbar->priv->model, toolbar_position, position);
648 item = create_item_from_action (etoolbar, name);
654 toolbar_drag_data_received_cb (GtkToolbar *toolbar,
655 GdkDragContext *context,
658 GtkSelectionData *selection_data,
661 EggEditableToolbar *etoolbar)
663 /* This function can be called for two reasons
665 * (1) drag_motion() needs an item to pass to
666 * gtk_toolbar_set_drop_highlight_item(). We can
667 * recognize this case by etoolbar->priv->pending being TRUE
668 * We should just create an item and return.
670 * (2) The drag has finished, and drag_drop() wants us to
671 * actually add a new item to the toolbar.
674 GdkAtom type = selection_data->type;
675 const char *data = (char *)selection_data->data;
679 gboolean used = FALSE;
681 /* Find out where the drop is occuring, and the name of what is being dropped. */
682 if (selection_data->length >= 0)
684 ipos = gtk_toolbar_get_drop_index (toolbar, x, y);
685 name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, FALSE);
688 used = ((egg_toolbars_model_get_name_flags (etoolbar->priv->model, name) & EGG_TB_MODEL_NAME_USED) != 0);
692 /* If we just want a highlight item, then . */
693 if (etoolbar->priv->dnd_pending > 0)
695 etoolbar->priv->dnd_pending--;
697 if (name != NULL && etoolbar->priv->dnd_toolbar == toolbar && !used)
699 etoolbar->priv->dnd_toolitem = create_item_from_action (etoolbar, name);
700 gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar,
701 etoolbar->priv->dnd_toolitem, ipos);
706 gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
707 etoolbar->priv->dnd_toolbar = NULL;
708 etoolbar->priv->dnd_toolitem = NULL;
710 /* If we don't have a name to use yet, try to create one. */
711 if (name == NULL && selection_data->length >= 0)
713 name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, TRUE);
716 if (name != NULL && !used)
718 gint tpos = get_toolbar_position (etoolbar, GTK_WIDGET (toolbar));
719 egg_toolbars_model_add_item (etoolbar->priv->model, tpos, ipos, name);
720 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
724 gtk_drag_finish (context, FALSE, context->action == GDK_ACTION_MOVE, time);
732 toolbar_drag_drop_cb (GtkToolbar *toolbar,
733 GdkDragContext *context,
737 EggEditableToolbar *etoolbar)
741 target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL);
742 if (target != GDK_NONE)
744 gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
752 toolbar_drag_motion_cb (GtkToolbar *toolbar,
753 GdkDragContext *context,
757 EggEditableToolbar *etoolbar)
759 GdkAtom target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL);
760 if (target == GDK_NONE)
762 gdk_drag_status (context, 0, time);
766 /* Make ourselves the current dnd toolbar, and request a highlight item. */
767 if (etoolbar->priv->dnd_toolbar != toolbar)
769 etoolbar->priv->dnd_toolbar = toolbar;
770 etoolbar->priv->dnd_toolitem = NULL;
771 etoolbar->priv->dnd_pending++;
772 gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
775 /* If a highlight item is available, use it. */
776 else if (etoolbar->priv->dnd_toolitem)
778 gint ipos = gtk_toolbar_get_drop_index (etoolbar->priv->dnd_toolbar, x, y);
779 gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar,
780 etoolbar->priv->dnd_toolitem, ipos);
783 gdk_drag_status (context, context->suggested_action, time);
789 toolbar_drag_leave_cb (GtkToolbar *toolbar,
790 GdkDragContext *context,
792 EggEditableToolbar *etoolbar)
794 gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
796 /* If we were the current dnd toolbar target, remove the item. */
797 if (etoolbar->priv->dnd_toolbar == toolbar)
799 etoolbar->priv->dnd_toolbar = NULL;
800 etoolbar->priv->dnd_toolitem = NULL;
805 configure_drag_dest (EggEditableToolbar *etoolbar,
808 EggToolbarsItemType *type;
809 GtkTargetList *targets;
812 /* Make every toolbar able to receive drag-drops. */
813 gtk_drag_dest_set (GTK_WIDGET (toolbar), 0,
814 dest_drag_types, G_N_ELEMENTS (dest_drag_types),
815 GDK_ACTION_MOVE | GDK_ACTION_COPY);
817 /* Add any specialist drag-drop abilities. */
818 targets = gtk_drag_dest_get_target_list (GTK_WIDGET (toolbar));
819 list = egg_toolbars_model_get_types (etoolbar->priv->model);
823 if (type->new_name != NULL || type->get_name != NULL)
824 gtk_target_list_add (targets, type->type, 0, 0);
830 toggled_visibility_cb (GtkToggleAction *action,
831 EggEditableToolbar *etoolbar)
833 EggEditableToolbarPrivate *priv = etoolbar->priv;
835 EggTbModelFlags flags;
839 visible = gtk_toggle_action_get_active (action);
840 for (i = 0; i < priv->visibility_actions->len; i++)
841 if (g_ptr_array_index (priv->visibility_actions, i) == action)
844 g_return_if_fail (i < priv->visibility_actions->len);
846 dock = get_dock_nth (etoolbar, i);
849 gtk_widget_show (dock);
853 gtk_widget_hide (dock);
856 if (priv->save_hidden)
858 flags = egg_toolbars_model_get_flags (priv->model, i);
862 flags &= ~(EGG_TB_MODEL_HIDDEN);
866 flags |= (EGG_TB_MODEL_HIDDEN);
869 egg_toolbars_model_set_flags (priv->model, i, flags);
874 toolbar_visibility_refresh (EggEditableToolbar *etoolbar)
876 EggEditableToolbarPrivate *priv = etoolbar->priv;
877 gint n_toolbars, n_items, i, j, k;
878 GtkToggleAction *action;
882 char action_name[40];
886 if (priv == NULL || priv->model == NULL || priv->manager == NULL ||
887 priv->visibility_paths == NULL || priv->actions == NULL)
892 if (priv->visibility_actions == NULL)
894 priv->visibility_actions = g_ptr_array_new ();
897 if (priv->visibility_id != 0)
899 gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
902 priv->visibility_id = gtk_ui_manager_new_merge_id (priv->manager);
904 showing = GTK_WIDGET_VISIBLE (etoolbar);
906 n_toolbars = egg_toolbars_model_n_toolbars (priv->model);
907 for (i = 0; i < n_toolbars; i++)
909 string = g_string_sized_new (0);
910 n_items = egg_toolbars_model_n_items (priv->model, i);
911 for (k = 0, j = 0; j < n_items; j++)
913 GValue value = { 0, };
917 name = egg_toolbars_model_item_nth (priv->model, i, j);
918 if (name == NULL) continue;
919 action = find_action (etoolbar, name);
920 if (action == NULL) continue;
922 g_value_init (&value, G_TYPE_STRING);
923 g_object_get_property (G_OBJECT (action), "label", &value);
924 name = g_value_get_string (&value);
927 g_value_unset (&value);
930 k += g_utf8_strlen (name, -1) + 2;
933 g_string_append (string, ", ");
936 g_value_unset (&value);
940 g_string_append (string, name);
941 g_value_unset (&value);
945 g_string_append (string, " ...");
948 tmp = g_string_free (string, FALSE);
949 for (j = 0, k = 0; tmp[j]; j++)
951 if (tmp[j] == '_') continue;
956 /* Translaters: This string is for a toggle to display a toolbar.
957 * The name of the toolbar is automatically computed from the widgets
958 * on the toolbar, and is placed at the %s. Note the _ before the %s
959 * which is used to add mnemonics. We know that this is likely to
960 * produce duplicates, but don't worry about it. If your language
961 * normally has a mnemonic at the start, please use the _. If not,
963 action_label = g_strdup_printf (_("Show “_%s”"), tmp);
966 sprintf(action_name, "ToolbarToggle%d", i);
968 if (i >= priv->visibility_actions->len)
970 action = gtk_toggle_action_new (action_name, action_label, NULL, NULL);
971 g_ptr_array_add (priv->visibility_actions, action);
972 g_signal_connect_object (action, "toggled",
973 G_CALLBACK (toggled_visibility_cb),
975 gtk_action_group_add_action (priv->actions, GTK_ACTION (action));
979 action = g_ptr_array_index (priv->visibility_actions, i);
980 g_object_set (action, "label", action_label, NULL);
983 gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i)
984 & EGG_TB_MODEL_NOT_REMOVABLE) == 0);
985 gtk_action_set_sensitive (GTK_ACTION (action), showing);
986 gtk_toggle_action_set_active (action, GTK_WIDGET_VISIBLE
987 (get_dock_nth (etoolbar, i)));
989 for (list = priv->visibility_paths; list != NULL; list = g_list_next (list))
991 gtk_ui_manager_add_ui (priv->manager, priv->visibility_id,
992 (const char *)list->data, action_name, action_name,
993 GTK_UI_MANAGER_MENUITEM, FALSE);
996 g_free (action_label);
999 gtk_ui_manager_ensure_update (priv->manager);
1001 while (i < priv->visibility_actions->len)
1003 action = g_ptr_array_index (priv->visibility_actions, i);
1004 g_ptr_array_remove_index_fast (priv->visibility_actions, i);
1005 gtk_action_group_remove_action (priv->actions, GTK_ACTION (action));
1011 create_dock (EggEditableToolbar *etoolbar)
1013 GtkWidget *toolbar, *hbox;
1015 hbox = gtk_hbox_new (0, FALSE);
1017 toolbar = gtk_toolbar_new ();
1018 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
1019 gtk_widget_show (toolbar);
1020 gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0);
1022 g_signal_connect (toolbar, "drag_drop",
1023 G_CALLBACK (toolbar_drag_drop_cb), etoolbar);
1024 g_signal_connect (toolbar, "drag_motion",
1025 G_CALLBACK (toolbar_drag_motion_cb), etoolbar);
1026 g_signal_connect (toolbar, "drag_leave",
1027 G_CALLBACK (toolbar_drag_leave_cb), etoolbar);
1029 g_signal_connect (toolbar, "drag_data_received",
1030 G_CALLBACK (toolbar_drag_data_received_cb), etoolbar);
1031 g_signal_connect (toolbar, "popup_context_menu",
1032 G_CALLBACK (popup_context_menu_cb), etoolbar);
1034 configure_drag_dest (etoolbar, GTK_TOOLBAR (toolbar));
1040 set_fixed_style (EggEditableToolbar *t, GtkToolbarStyle style)
1042 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
1043 gtk_toolbar_set_style (GTK_TOOLBAR (t->priv->fixed_toolbar),
1044 style == GTK_TOOLBAR_ICONS ? GTK_TOOLBAR_BOTH_HORIZ : style);
1048 unset_fixed_style (EggEditableToolbar *t)
1050 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
1051 gtk_toolbar_unset_style (GTK_TOOLBAR (t->priv->fixed_toolbar));
1055 toolbar_changed_cb (EggToolbarsModel *model,
1057 EggEditableToolbar *etoolbar)
1060 EggTbModelFlags flags;
1061 GtkToolbarStyle style;
1063 flags = egg_toolbars_model_get_flags (model, position);
1064 toolbar = get_toolbar_nth (etoolbar, position);
1066 if (flags & EGG_TB_MODEL_ICONS)
1068 style = GTK_TOOLBAR_ICONS;
1070 else if (flags & EGG_TB_MODEL_TEXT)
1072 style = GTK_TOOLBAR_TEXT;
1074 else if (flags & EGG_TB_MODEL_BOTH)
1076 style = GTK_TOOLBAR_BOTH;
1078 else if (flags & EGG_TB_MODEL_BOTH_HORIZ)
1080 style = GTK_TOOLBAR_BOTH_HORIZ;
1084 gtk_toolbar_unset_style (GTK_TOOLBAR (toolbar));
1085 if (position == 0 && etoolbar->priv->fixed_toolbar)
1087 unset_fixed_style (etoolbar);
1092 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style);
1093 if (position == 0 && etoolbar->priv->fixed_toolbar)
1095 set_fixed_style (etoolbar, style);
1098 toolbar_visibility_refresh (etoolbar);
1102 unparent_fixed (EggEditableToolbar *etoolbar)
1104 GtkWidget *toolbar, *dock;
1105 g_return_if_fail (GTK_IS_TOOLBAR (etoolbar->priv->fixed_toolbar));
1107 toolbar = etoolbar->priv->fixed_toolbar;
1108 dock = get_dock_nth (etoolbar, 0);
1110 if (dock && toolbar->parent != NULL)
1112 gtk_container_remove (GTK_CONTAINER (dock), toolbar);
1117 update_fixed (EggEditableToolbar *etoolbar)
1119 GtkWidget *toolbar, *dock;
1120 if (!etoolbar->priv->fixed_toolbar) return;
1122 toolbar = etoolbar->priv->fixed_toolbar;
1123 dock = get_dock_nth (etoolbar, 0);
1125 if (dock && toolbar && toolbar->parent == NULL)
1127 gtk_box_pack_end (GTK_BOX (dock), toolbar, FALSE, TRUE, 0);
1129 gtk_widget_show (toolbar);
1131 gtk_widget_set_size_request (dock, -1, -1);
1132 gtk_widget_queue_resize_no_redraw (dock);
1137 toolbar_added_cb (EggToolbarsModel *model,
1139 EggEditableToolbar *etoolbar)
1143 dock = create_dock (etoolbar);
1144 if ((egg_toolbars_model_get_flags (model, position) & EGG_TB_MODEL_HIDDEN) == 0)
1145 gtk_widget_show (dock);
1147 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1149 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1151 gtk_box_reorder_child (GTK_BOX (etoolbar), dock, position);
1153 gtk_widget_show_all (dock);
1155 update_fixed (etoolbar);
1157 toolbar_visibility_refresh (etoolbar);
1161 toolbar_removed_cb (EggToolbarsModel *model,
1163 EggEditableToolbar *etoolbar)
1167 if (position == 0 && etoolbar->priv->fixed_toolbar != NULL)
1169 unparent_fixed (etoolbar);
1172 dock = get_dock_nth (etoolbar, position);
1173 gtk_widget_destroy (dock);
1175 update_fixed (etoolbar);
1177 toolbar_visibility_refresh (etoolbar);
1181 item_added_cb (EggToolbarsModel *model,
1184 EggEditableToolbar *etoolbar)
1190 toolbar = get_toolbar_nth (etoolbar, tpos);
1191 item = create_item_from_position (etoolbar, tpos, ipos);
1192 if (item == NULL) return;
1194 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, ipos);
1196 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1197 configure_item_tooltip (item);
1198 configure_item_cursor (item, etoolbar);
1199 configure_item_sensitivity (item, etoolbar);
1201 dock = get_dock_nth (etoolbar, tpos);
1202 gtk_widget_set_size_request (dock, -1, -1);
1203 gtk_widget_queue_resize_no_redraw (dock);
1205 toolbar_visibility_refresh (etoolbar);
1209 item_removed_cb (EggToolbarsModel *model,
1210 int toolbar_position,
1212 EggEditableToolbar *etoolbar)
1214 EggEditableToolbarPrivate *priv = etoolbar->priv;
1219 toolbar = get_toolbar_nth (etoolbar, toolbar_position);
1220 item = GTK_WIDGET (gtk_toolbar_get_nth_item
1221 (GTK_TOOLBAR (toolbar), position));
1222 g_return_if_fail (item != NULL);
1224 if (item == priv->selected)
1229 gtk_container_remove (GTK_CONTAINER (toolbar), item);
1231 toolbar_visibility_refresh (etoolbar);
1235 egg_editable_toolbar_build (EggEditableToolbar *etoolbar)
1237 int i, l, n_items, n_toolbars;
1238 EggToolbarsModel *model = etoolbar->priv->model;
1240 g_return_if_fail (model != NULL);
1241 g_return_if_fail (etoolbar->priv->manager != NULL);
1243 n_toolbars = egg_toolbars_model_n_toolbars (model);
1245 for (i = 0; i < n_toolbars; i++)
1247 GtkWidget *toolbar, *dock;
1249 dock = create_dock (etoolbar);
1250 if ((egg_toolbars_model_get_flags (model, i) & EGG_TB_MODEL_HIDDEN) == 0)
1251 gtk_widget_show (dock);
1252 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1253 toolbar = get_toolbar_nth (etoolbar, i);
1255 n_items = egg_toolbars_model_n_items (model, i);
1256 for (l = 0; l < n_items; l++)
1260 item = create_item_from_position (etoolbar, i, l);
1263 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, l);
1265 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1266 configure_item_tooltip (item);
1267 configure_item_sensitivity (item, etoolbar);
1271 egg_toolbars_model_remove_item (model, i, l);
1279 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1283 update_fixed (etoolbar);
1286 for (i = 0; i < n_toolbars; i ++)
1288 toolbar_changed_cb (model, i, etoolbar);
1293 egg_editable_toolbar_disconnect_model (EggEditableToolbar *toolbar)
1295 EggToolbarsModel *model = toolbar->priv->model;
1297 g_signal_handlers_disconnect_by_func
1298 (model, G_CALLBACK (item_added_cb), toolbar);
1299 g_signal_handlers_disconnect_by_func
1300 (model, G_CALLBACK (item_removed_cb), toolbar);
1301 g_signal_handlers_disconnect_by_func
1302 (model, G_CALLBACK (toolbar_added_cb), toolbar);
1303 g_signal_handlers_disconnect_by_func
1304 (model, G_CALLBACK (toolbar_removed_cb), toolbar);
1305 g_signal_handlers_disconnect_by_func
1306 (model, G_CALLBACK (toolbar_changed_cb), toolbar);
1310 egg_editable_toolbar_deconstruct (EggEditableToolbar *toolbar)
1312 EggToolbarsModel *model = toolbar->priv->model;
1315 g_return_if_fail (model != NULL);
1317 if (toolbar->priv->fixed_toolbar)
1319 unset_fixed_style (toolbar);
1320 unparent_fixed (toolbar);
1323 children = gtk_container_get_children (GTK_CONTAINER (toolbar));
1324 g_list_foreach (children, (GFunc) gtk_widget_destroy, NULL);
1325 g_list_free (children);
1329 egg_editable_toolbar_set_model (EggEditableToolbar *etoolbar,
1330 EggToolbarsModel *model)
1332 EggEditableToolbarPrivate *priv = etoolbar->priv;
1334 if (priv->model == model) return;
1338 egg_editable_toolbar_disconnect_model (etoolbar);
1339 egg_editable_toolbar_deconstruct (etoolbar);
1341 g_object_unref (priv->model);
1344 priv->model = g_object_ref (model);
1346 egg_editable_toolbar_build (etoolbar);
1348 toolbar_visibility_refresh (etoolbar);
1350 g_signal_connect (model, "item_added",
1351 G_CALLBACK (item_added_cb), etoolbar);
1352 g_signal_connect (model, "item_removed",
1353 G_CALLBACK (item_removed_cb), etoolbar);
1354 g_signal_connect (model, "toolbar_added",
1355 G_CALLBACK (toolbar_added_cb), etoolbar);
1356 g_signal_connect (model, "toolbar_removed",
1357 G_CALLBACK (toolbar_removed_cb), etoolbar);
1358 g_signal_connect (model, "toolbar_changed",
1359 G_CALLBACK (toolbar_changed_cb), etoolbar);
1363 egg_editable_toolbar_init (EggEditableToolbar *etoolbar)
1365 EggEditableToolbarPrivate *priv;
1367 priv = etoolbar->priv = EGG_EDITABLE_TOOLBAR_GET_PRIVATE (etoolbar);
1369 priv->save_hidden = TRUE;
1371 g_signal_connect (etoolbar, "notify::visible",
1372 G_CALLBACK (toolbar_visibility_refresh), NULL);
1376 egg_editable_toolbar_dispose (GObject *object)
1378 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1379 EggEditableToolbarPrivate *priv = etoolbar->priv;
1382 if (priv->fixed_toolbar != NULL)
1384 g_object_unref (priv->fixed_toolbar);
1385 priv->fixed_toolbar = NULL;
1388 if (priv->visibility_paths)
1390 children = priv->visibility_paths;
1391 g_list_foreach (children, (GFunc) g_free, NULL);
1392 g_list_free (children);
1393 priv->visibility_paths = NULL;
1396 if (priv->manager != NULL)
1398 if (priv->visibility_id)
1400 gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
1401 priv->visibility_id = 0;
1404 g_object_unref (priv->manager);
1405 priv->manager = NULL;
1410 egg_editable_toolbar_disconnect_model (etoolbar);
1411 g_object_unref (priv->model);
1415 G_OBJECT_CLASS (parent_class)->dispose (object);
1419 egg_editable_toolbar_set_ui_manager (EggEditableToolbar *etoolbar,
1420 GtkUIManager *manager)
1422 static const GtkActionEntry actions[] = {
1423 { "MoveToolItem", STOCK_DRAG_MODE, N_("_Move on Toolbar"), NULL,
1424 N_("Move the selected item on the toolbar"), G_CALLBACK (move_item_cb) },
1425 { "RemoveToolItem", GTK_STOCK_REMOVE, N_("_Remove from Toolbar"), NULL,
1426 N_("Remove the selected item from the toolbar"), G_CALLBACK (remove_item_cb) },
1427 { "RemoveToolbar", GTK_STOCK_DELETE, N_("_Delete Toolbar"), NULL,
1428 N_("Remove the selected toolbar"), G_CALLBACK (remove_toolbar_cb) },
1431 etoolbar->priv->manager = g_object_ref (manager);
1433 etoolbar->priv->actions = gtk_action_group_new ("ToolbarActions");
1434 gtk_action_group_set_translation_domain (etoolbar->priv->actions, GETTEXT_PACKAGE);
1435 gtk_action_group_add_actions (etoolbar->priv->actions, actions,
1436 G_N_ELEMENTS (actions), etoolbar);
1437 gtk_ui_manager_insert_action_group (manager, etoolbar->priv->actions, -1);
1438 g_object_unref (etoolbar->priv->actions);
1440 toolbar_visibility_refresh (etoolbar);
1443 GtkWidget * egg_editable_toolbar_get_selected (EggEditableToolbar *etoolbar)
1445 return etoolbar->priv->selected;
1449 egg_editable_toolbar_set_selected (EggEditableToolbar *etoolbar,
1452 GtkWidget *toolbar, *toolitem;
1455 etoolbar->priv->selected = widget;
1457 toolbar = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR) : NULL;
1458 toolitem = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM) : NULL;
1462 gint tpos = get_toolbar_position (etoolbar, toolbar);
1463 editable = ((egg_toolbars_model_get_flags (etoolbar->priv->model, tpos) & EGG_TB_MODEL_NOT_EDITABLE) == 0);
1470 gtk_action_set_visible (find_action (etoolbar, "RemoveToolbar"), (toolbar != NULL) && (etoolbar->priv->edit_mode > 0));
1471 gtk_action_set_visible (find_action (etoolbar, "RemoveToolItem"), (toolitem != NULL) && editable);
1472 gtk_action_set_visible (find_action (etoolbar, "MoveToolItem"), (toolitem != NULL) && editable);
1476 set_edit_mode (EggEditableToolbar *etoolbar,
1479 EggEditableToolbarPrivate *priv = etoolbar->priv;
1482 i = priv->edit_mode;
1489 g_return_if_fail (priv->edit_mode > 0);
1492 i *= priv->edit_mode;
1496 for (i = get_n_toolbars (etoolbar)-1; i >= 0; i--)
1500 toolbar = get_toolbar_nth (etoolbar, i);
1501 n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
1503 if (n_items == 0 && priv->edit_mode == 0)
1505 egg_toolbars_model_remove_toolbar (priv->model, i);
1509 for (l = 0; l < n_items; l++)
1513 item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
1515 configure_item_cursor (item, etoolbar);
1516 configure_item_sensitivity (item, etoolbar);
1524 egg_editable_toolbar_set_property (GObject *object,
1526 const GValue *value,
1529 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1533 case PROP_UI_MANAGER:
1534 egg_editable_toolbar_set_ui_manager (etoolbar, g_value_get_object (value));
1536 case PROP_TOOLBARS_MODEL:
1537 egg_editable_toolbar_set_model (etoolbar, g_value_get_object (value));
1540 egg_editable_toolbar_set_selected (etoolbar, g_value_get_object (value));
1542 case PROP_POPUP_PATH:
1543 etoolbar->priv->popup_path = g_strdup (g_value_get_string (value));
1545 case PROP_EDIT_MODE:
1546 set_edit_mode (etoolbar, g_value_get_boolean (value));
1549 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1555 egg_editable_toolbar_get_property (GObject *object,
1560 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1564 case PROP_UI_MANAGER:
1565 g_value_set_object (value, etoolbar->priv->manager);
1567 case PROP_TOOLBARS_MODEL:
1568 g_value_set_object (value, etoolbar->priv->model);
1571 g_value_set_object (value, etoolbar->priv->selected);
1573 case PROP_EDIT_MODE:
1574 g_value_set_boolean (value, etoolbar->priv->edit_mode>0);
1577 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1583 egg_editable_toolbar_class_init (EggEditableToolbarClass *klass)
1585 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1587 parent_class = g_type_class_peek_parent (klass);
1589 object_class->dispose = egg_editable_toolbar_dispose;
1590 object_class->set_property = egg_editable_toolbar_set_property;
1591 object_class->get_property = egg_editable_toolbar_get_property;
1593 egg_editable_toolbar_signals[ACTION_REQUEST] =
1594 g_signal_new ("action_request",
1595 G_OBJECT_CLASS_TYPE (object_class),
1597 G_STRUCT_OFFSET (EggEditableToolbarClass, action_request),
1598 NULL, NULL, g_cclosure_marshal_VOID__STRING,
1599 G_TYPE_NONE, 1, G_TYPE_STRING);
1601 g_object_class_install_property (object_class,
1603 g_param_spec_object ("ui-manager",
1606 GTK_TYPE_UI_MANAGER,
1607 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1608 g_object_class_install_property (object_class,
1609 PROP_TOOLBARS_MODEL,
1610 g_param_spec_object ("model",
1613 EGG_TYPE_TOOLBARS_MODEL,
1614 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1615 g_object_class_install_property (object_class,
1617 g_param_spec_object ("selected",
1619 "Selected toolitem",
1621 G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1623 g_object_class_install_property (object_class,
1625 g_param_spec_string ("popup-path",
1629 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1631 g_object_class_install_property (object_class,
1633 g_param_spec_boolean ("edit-mode",
1637 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1639 g_type_class_add_private (object_class, sizeof (EggEditableToolbarPrivate));
1643 egg_editable_toolbar_new (GtkUIManager *manager,
1644 const char *popup_path)
1646 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1647 "ui-manager", manager,
1648 "popup-path", popup_path,
1653 egg_editable_toolbar_new_with_model (GtkUIManager *manager,
1654 EggToolbarsModel *model,
1655 const char *popup_path)
1657 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1658 "ui-manager", manager,
1660 "popup-path", popup_path,
1665 egg_editable_toolbar_get_edit_mode (EggEditableToolbar *etoolbar)
1667 EggEditableToolbarPrivate *priv = etoolbar->priv;
1669 return priv->edit_mode > 0;
1673 egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar,
1676 set_edit_mode (etoolbar, mode);
1677 g_object_notify (G_OBJECT (etoolbar), "edit-mode");
1681 egg_editable_toolbar_add_visibility (EggEditableToolbar *etoolbar,
1684 etoolbar->priv->visibility_paths = g_list_prepend
1685 (etoolbar->priv->visibility_paths, g_strdup (path));
1689 egg_editable_toolbar_show (EggEditableToolbar *etoolbar,
1692 EggEditableToolbarPrivate *priv = etoolbar->priv;
1693 EggToolbarsModel *model = priv->model;
1696 n_toolbars = egg_toolbars_model_n_toolbars (model);
1697 for (i = 0; i < n_toolbars; i++)
1699 const char *toolbar_name;
1701 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1702 if (strcmp (toolbar_name, name) == 0)
1704 gtk_widget_show (get_dock_nth (etoolbar, i));
1710 egg_editable_toolbar_hide (EggEditableToolbar *etoolbar,
1713 EggEditableToolbarPrivate *priv = etoolbar->priv;
1714 EggToolbarsModel *model = priv->model;
1717 n_toolbars = egg_toolbars_model_n_toolbars (model);
1718 for (i = 0; i < n_toolbars; i++)
1720 const char *toolbar_name;
1722 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1723 if (strcmp (toolbar_name, name) == 0)
1725 gtk_widget_hide (get_dock_nth (etoolbar, i));
1731 egg_editable_toolbar_set_fixed (EggEditableToolbar *etoolbar,
1732 GtkToolbar *toolbar)
1734 EggEditableToolbarPrivate *priv = etoolbar->priv;
1736 g_return_if_fail (!toolbar || GTK_IS_TOOLBAR (toolbar));
1738 if (priv->fixed_toolbar)
1740 unparent_fixed (etoolbar);
1741 g_object_unref (priv->fixed_toolbar);
1742 priv->fixed_toolbar = NULL;
1747 priv->fixed_toolbar = GTK_WIDGET (toolbar);
1748 gtk_toolbar_set_show_arrow (toolbar, FALSE);
1749 g_object_ref_sink (toolbar);
1752 update_fixed (etoolbar);
1755 #define DEFAULT_ICON_HEIGHT 20
1756 #define DEFAULT_ICON_WIDTH 0
1759 fake_expose_widget (GtkWidget *widget,
1762 GdkWindow *tmp_window;
1763 GdkEventExpose event;
1765 event.type = GDK_EXPOSE;
1766 event.window = pixmap;
1767 event.send_event = FALSE;
1768 event.area = widget->allocation;
1769 event.region = NULL;
1772 tmp_window = widget->window;
1773 widget->window = pixmap;
1774 gtk_widget_send_expose (widget, (GdkEvent *) &event);
1775 widget->window = tmp_window;
1778 /* We should probably experiment some more with this.
1779 * Right now the rendered icon is pretty good for most
1780 * themes. However, the icon is slightly large for themes
1781 * with large toolbar icons.
1784 new_pixbuf_from_widget (GtkWidget *widget)
1788 GtkRequisition requisition;
1789 GtkAllocation allocation;
1795 icon_width = DEFAULT_ICON_WIDTH;
1797 if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_default (),
1798 GTK_ICON_SIZE_LARGE_TOOLBAR,
1802 icon_height = DEFAULT_ICON_HEIGHT;
1805 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1807 gtk_container_add (GTK_CONTAINER (window), widget);
1808 gtk_widget_realize (window);
1809 gtk_widget_show (widget);
1810 gtk_widget_realize (widget);
1811 gtk_widget_map (widget);
1813 /* Gtk will never set the width or height of a window to 0. So setting the width to
1814 * 0 and than getting it will provide us with the minimum width needed to render
1815 * the icon correctly, without any additional window background noise.
1816 * This is needed mostly for pixmap based themes.
1818 gtk_window_set_default_size (GTK_WINDOW (window), icon_width, icon_height);
1819 gtk_window_get_size (GTK_WINDOW (window),&icon_width, &icon_height);
1821 gtk_widget_size_request (window, &requisition);
1824 allocation.width = icon_width;
1825 allocation.height = icon_height;
1826 gtk_widget_size_allocate (window, &allocation);
1827 gtk_widget_size_request (window, &requisition);
1829 /* Create a pixmap */
1830 visual = gtk_widget_get_visual (window);
1831 pixmap = gdk_pixmap_new (NULL, icon_width, icon_height, visual->depth);
1832 gdk_drawable_set_colormap (GDK_DRAWABLE (pixmap), gtk_widget_get_colormap (window));
1834 /* Draw the window */
1835 gtk_widget_ensure_style (window);
1836 g_assert (window->style);
1837 g_assert (window->style->font_desc);
1839 fake_expose_widget (window, pixmap);
1840 fake_expose_widget (widget, pixmap);
1842 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, icon_width, icon_height);
1843 gdk_pixbuf_get_from_drawable (pixbuf, pixmap, NULL, 0, 0, 0, 0, icon_width, icon_height);
1845 gtk_widget_destroy (window);
1851 new_separator_pixbuf ()
1853 GtkWidget *separator;
1856 separator = gtk_vseparator_new ();
1857 pixbuf = new_pixbuf_from_widget (separator);
1862 update_separator_image (GtkImage *image)
1864 GdkPixbuf *pixbuf = new_separator_pixbuf ();
1865 gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
1866 g_object_unref (pixbuf);
1870 style_set_cb (GtkWidget *widget,
1871 GtkStyle *previous_style,
1875 update_separator_image (image);
1880 _egg_editable_toolbar_new_separator_image (void)
1882 GtkWidget *image = gtk_image_new ();
1883 update_separator_image (GTK_IMAGE (image));
1884 g_signal_connect (G_OBJECT (image), "style_set",
1885 G_CALLBACK (style_set_cb), GTK_IMAGE (image));
1891 egg_editable_toolbar_get_model (EggEditableToolbar *etoolbar)
1893 return etoolbar->priv->model;