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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "egg-editable-toolbar.h"
25 #include "egg-toolbars-model.h"
26 #include "egg-toolbar-editor.h"
29 #include <glib/gi18n.h>
32 static GdkPixbuf * new_separator_pixbuf (void);
34 #define MIN_TOOLBAR_HEIGHT 20
35 #define EGG_ITEM_NAME "egg-item-name"
36 #define STOCK_DRAG_MODE "stock_drag-mode"
38 static const GtkTargetEntry dest_drag_types[] = {
39 {EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0},
58 static guint egg_editable_toolbar_signals[LAST_SIGNAL] = { 0 };
60 #define EGG_EDITABLE_TOOLBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EGG_TYPE_EDITABLE_TOOLBAR, EggEditableToolbarPrivate))
62 struct _EggEditableToolbarPrivate
64 GtkUIManager *manager;
65 EggToolbarsModel *model;
68 GtkWidget *fixed_toolbar;
71 GtkActionGroup *actions;
74 GList *visibility_paths;
75 GPtrArray *visibility_actions;
80 GtkToolbar *dnd_toolbar;
81 GtkToolItem *dnd_toolitem;
84 G_DEFINE_TYPE (EggEditableToolbar, egg_editable_toolbar, GTK_TYPE_VBOX);
87 get_dock_position (EggEditableToolbar *etoolbar,
93 l = gtk_container_get_children (GTK_CONTAINER (etoolbar));
94 result = g_list_index (l, dock);
101 get_toolbar_position (EggEditableToolbar *etoolbar, GtkWidget *toolbar)
103 return get_dock_position (etoolbar, gtk_widget_get_parent (toolbar));
107 get_n_toolbars (EggEditableToolbar *etoolbar)
112 l = gtk_container_get_children (GTK_CONTAINER (etoolbar));
113 result = g_list_length (l);
120 get_dock_nth (EggEditableToolbar *etoolbar,
126 l = gtk_container_get_children (GTK_CONTAINER (etoolbar));
127 result = g_list_nth_data (l, position);
134 get_toolbar_nth (EggEditableToolbar *etoolbar,
141 dock = get_dock_nth (etoolbar, position);
142 g_return_val_if_fail (dock != NULL, NULL);
144 l = gtk_container_get_children (GTK_CONTAINER (dock));
145 result = GTK_WIDGET (l->data);
152 find_action (EggEditableToolbar *etoolbar,
156 GtkAction *action = NULL;
158 l = gtk_ui_manager_get_action_groups (etoolbar->priv->manager);
160 g_return_val_if_fail (name != NULL, NULL);
162 for (; l != NULL; l = l->next)
166 tmp = gtk_action_group_get_action (GTK_ACTION_GROUP (l->data), name);
175 drag_data_delete_cb (GtkWidget *widget,
176 GdkDragContext *context,
177 EggEditableToolbar *etoolbar)
179 int pos, toolbar_pos;
182 widget = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
183 g_return_if_fail (widget != NULL);
184 g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
186 parent = gtk_widget_get_parent (widget);
187 pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (parent),
188 GTK_TOOL_ITEM (widget));
189 toolbar_pos = get_toolbar_position (etoolbar, parent);
191 egg_toolbars_model_remove_item (etoolbar->priv->model,
196 drag_begin_cb (GtkWidget *widget,
197 GdkDragContext *context,
198 EggEditableToolbar *etoolbar)
203 gtk_widget_hide (widget);
205 #if GTK_CHECK_VERSION (2, 16, 0)
206 action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
208 action = gtk_widget_get_action (widget);
211 if (action == NULL) return;
213 flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model,
214 gtk_action_get_name (action));
215 if (!(flags & EGG_TB_MODEL_NAME_INFINITE))
217 flags &= ~EGG_TB_MODEL_NAME_USED;
218 egg_toolbars_model_set_name_flags (etoolbar->priv->model,
219 gtk_action_get_name (action),
225 drag_end_cb (GtkWidget *widget,
226 GdkDragContext *context,
227 EggEditableToolbar *etoolbar)
232 if (gtk_widget_get_parent (widget) != NULL)
234 gtk_widget_show (widget);
236 #if GTK_CHECK_VERSION (2, 16, 0)
237 action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
239 action = gtk_widget_get_action (widget);
242 if (action == NULL) return;
244 flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model,
245 gtk_action_get_name (action));
246 if (!(flags & EGG_TB_MODEL_NAME_INFINITE))
248 flags |= EGG_TB_MODEL_NAME_USED;
249 egg_toolbars_model_set_name_flags (etoolbar->priv->model,
250 gtk_action_get_name (action),
257 drag_data_get_cb (GtkWidget *widget,
258 GdkDragContext *context,
259 GtkSelectionData *selection_data,
262 EggEditableToolbar *etoolbar)
264 EggToolbarsModel *model;
269 g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
270 model = egg_editable_toolbar_get_model (etoolbar);
272 name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
275 name = g_object_get_data (G_OBJECT (gtk_widget_get_parent (widget)), EGG_ITEM_NAME);
276 g_return_if_fail (name != NULL);
279 target = gtk_selection_data_get_target (selection_data);
280 data = egg_toolbars_model_get_data (model, target, name);
283 gtk_selection_data_set (selection_data, target, 8, (unsigned char *)data, strlen (data));
289 move_item_cb (GtkAction *action,
290 EggEditableToolbar *etoolbar)
292 GtkWidget *toolitem = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM);
293 GtkTargetList *list = gtk_target_list_new (dest_drag_types, G_N_ELEMENTS (dest_drag_types));
295 GdkEvent *realevent = gtk_get_current_event();
296 GdkEventMotion event;
297 event.type = GDK_MOTION_NOTIFY;
298 event.window = realevent->any.window;
299 event.send_event = FALSE;
301 event.time = gdk_event_get_time (realevent);
302 gdk_event_get_state (realevent, &event.state);
303 gdk_event_get_coords (realevent, &event.x, &event.y);
304 gdk_event_get_root_coords (realevent, &event.x_root, &event.y_root);
306 gtk_drag_begin (toolitem, list, GDK_ACTION_MOVE, 1, (GdkEvent *)&event);
307 gtk_target_list_unref (list);
311 remove_item_cb (GtkAction *action,
312 EggEditableToolbar *etoolbar)
314 GtkWidget *toolitem = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM);
315 GtkWidget *parent = gtk_widget_get_parent (toolitem);
316 int pos, toolbar_pos;
318 toolbar_pos = get_toolbar_position (etoolbar, parent);
319 pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (parent),
320 GTK_TOOL_ITEM (toolitem));
322 egg_toolbars_model_remove_item (etoolbar->priv->model,
325 if (egg_toolbars_model_n_items (etoolbar->priv->model, toolbar_pos) == 0)
327 egg_toolbars_model_remove_toolbar (etoolbar->priv->model, toolbar_pos);
332 remove_toolbar_cb (GtkAction *action,
333 EggEditableToolbar *etoolbar)
335 GtkWidget *selected = egg_editable_toolbar_get_selected (etoolbar);
336 GtkWidget *toolbar = gtk_widget_get_ancestor (selected, GTK_TYPE_TOOLBAR);
339 toolbar_pos = get_toolbar_position (etoolbar, toolbar);
340 egg_toolbars_model_remove_toolbar (etoolbar->priv->model, toolbar_pos);
344 popup_context_deactivate (GtkMenuShell *menu,
345 EggEditableToolbar *etoolbar)
347 egg_editable_toolbar_set_selected (etoolbar, NULL);
348 g_object_notify (G_OBJECT (etoolbar), "selected");
352 popup_context_menu_cb (GtkWidget *toolbar,
356 EggEditableToolbar *etoolbar)
358 if (etoolbar->priv->popup_path != NULL)
362 egg_editable_toolbar_set_selected (etoolbar, toolbar);
363 g_object_notify (G_OBJECT (etoolbar), "selected");
365 menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
366 etoolbar->priv->popup_path));
367 g_return_if_fail (menu != NULL);
368 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, button_number, gtk_get_current_event_time ());
369 g_signal_connect_object (menu, "selection-done",
370 G_CALLBACK (popup_context_deactivate),
376 button_press_event_cb (GtkWidget *widget,
377 GdkEventButton *event,
378 EggEditableToolbar *etoolbar)
380 if (event->button == 3 && etoolbar->priv->popup_path != NULL)
384 egg_editable_toolbar_set_selected (etoolbar, widget);
385 g_object_notify (G_OBJECT (etoolbar), "selected");
387 menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
388 etoolbar->priv->popup_path));
389 g_return_val_if_fail (menu != NULL, FALSE);
390 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button, event->time);
391 g_signal_connect_object (menu, "selection-done",
392 G_CALLBACK (popup_context_deactivate),
402 configure_item_sensitivity (GtkToolItem *item, EggEditableToolbar *etoolbar)
407 name = g_object_get_data (G_OBJECT (item), EGG_ITEM_NAME);
408 action = name ? find_action (etoolbar, name) : NULL;
412 g_object_notify (G_OBJECT (action), "sensitive");
415 gtk_tool_item_set_use_drag_window (item,
416 (etoolbar->priv->edit_mode > 0) ||
417 GTK_IS_SEPARATOR_TOOL_ITEM (item));
422 configure_item_cursor (GtkToolItem *item,
423 EggEditableToolbar *etoolbar)
425 EggEditableToolbarPrivate *priv = etoolbar->priv;
426 GtkWidget *widget = GTK_WIDGET (item);
427 GdkWindow *window = gtk_widget_get_window (widget);
431 if (priv->edit_mode > 0)
435 GdkPixbuf *pixbuf = NULL;
437 screen = gtk_widget_get_screen (GTK_WIDGET (etoolbar));
439 cursor = gdk_cursor_new_for_display (gdk_screen_get_display (screen),
441 gdk_window_set_cursor (window, cursor);
442 gdk_cursor_unref (cursor);
444 gtk_drag_source_set (widget, GDK_BUTTON1_MASK, dest_drag_types,
445 G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE);
446 if (GTK_IS_SEPARATOR_TOOL_ITEM (item))
448 pixbuf = new_separator_pixbuf ();
452 char *icon_name=NULL;
457 name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
458 action = name ? find_action (etoolbar, name) : NULL;
462 g_object_get (action,
463 "icon-name", &icon_name,
464 "stock-id", &stock_id,
470 GtkIconTheme *icon_theme;
471 GtkSettings *settings;
474 screen = gtk_widget_get_screen (widget);
475 icon_theme = gtk_icon_theme_get_for_screen (screen);
476 settings = gtk_settings_get_for_screen (screen);
478 if (!gtk_icon_size_lookup_for_settings (settings,
479 GTK_ICON_SIZE_LARGE_TOOLBAR,
485 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
486 MIN (width, height), 0, NULL);
490 pixbuf = gtk_widget_render_icon (widget, stock_id,
491 GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
497 if (G_UNLIKELY (!pixbuf))
501 gtk_drag_source_set_icon_pixbuf (widget, pixbuf);
502 g_object_unref (pixbuf);
507 gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET(item)), NULL);
514 configure_item_tooltip (GtkToolItem *item)
518 #if GTK_CHECK_VERSION (2, 16, 0)
519 action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (item));
521 action = gtk_widget_get_action (GTK_WIDGET (item));
526 g_object_notify (G_OBJECT (action), "tooltip");
532 connect_widget_signals (GtkWidget *proxy, EggEditableToolbar *etoolbar)
534 if (GTK_IS_CONTAINER (proxy))
536 gtk_container_forall (GTK_CONTAINER (proxy),
537 (GtkCallback) connect_widget_signals,
538 (gpointer) etoolbar);
541 if (GTK_IS_TOOL_ITEM (proxy))
543 g_signal_connect_object (proxy, "drag_begin",
544 G_CALLBACK (drag_begin_cb),
546 g_signal_connect_object (proxy, "drag_end",
547 G_CALLBACK (drag_end_cb),
549 g_signal_connect_object (proxy, "drag_data_get",
550 G_CALLBACK (drag_data_get_cb),
552 g_signal_connect_object (proxy, "drag_data_delete",
553 G_CALLBACK (drag_data_delete_cb),
557 if (GTK_IS_BUTTON (proxy) || GTK_IS_TOOL_ITEM (proxy))
559 g_signal_connect_object (proxy, "button-press-event",
560 G_CALLBACK (button_press_event_cb),
566 action_sensitive_cb (GtkAction *action,
570 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR
571 (gtk_widget_get_ancestor (GTK_WIDGET (item), EGG_TYPE_EDITABLE_TOOLBAR));
573 if (etoolbar->priv->edit_mode > 0)
575 gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
580 create_item_from_action (EggEditableToolbar *etoolbar,
585 g_return_val_if_fail (name != NULL, NULL);
587 if (strcmp (name, "_separator") == 0)
589 item = gtk_separator_tool_item_new ();
593 GtkAction *action = find_action (etoolbar, name);
594 if (action == NULL) return NULL;
596 item = GTK_TOOL_ITEM (gtk_action_create_tool_item (action));
598 /* Normally done on-demand by the GtkUIManager, but no
599 * such demand may have been made yet, so do it ourselves.
601 gtk_action_set_accel_group
602 (action, gtk_ui_manager_get_accel_group(etoolbar->priv->manager));
604 g_signal_connect_object (action, "notify::sensitive",
605 G_CALLBACK (action_sensitive_cb), item, 0);
608 gtk_widget_show (GTK_WIDGET (item));
610 g_object_set_data_full (G_OBJECT (item), EGG_ITEM_NAME,
611 g_strdup (name), g_free);
617 create_item_from_position (EggEditableToolbar *etoolbar,
618 int toolbar_position,
624 name = egg_toolbars_model_item_nth (etoolbar->priv->model, toolbar_position, position);
625 item = create_item_from_action (etoolbar, name);
631 toolbar_drag_data_received_cb (GtkToolbar *toolbar,
632 GdkDragContext *context,
635 GtkSelectionData *selection_data,
638 EggEditableToolbar *etoolbar)
640 /* This function can be called for two reasons
642 * (1) drag_motion() needs an item to pass to
643 * gtk_toolbar_set_drop_highlight_item(). We can
644 * recognize this case by etoolbar->priv->pending being TRUE
645 * We should just create an item and return.
647 * (2) The drag has finished, and drag_drop() wants us to
648 * actually add a new item to the toolbar.
651 GdkAtom type = gtk_selection_data_get_data_type (selection_data);
652 const char *data = (char *)gtk_selection_data_get_data (selection_data);
656 gboolean used = FALSE;
658 /* Find out where the drop is occuring, and the name of what is being dropped. */
659 if (gtk_selection_data_get_length (selection_data) >= 0)
661 ipos = gtk_toolbar_get_drop_index (toolbar, x, y);
662 name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, FALSE);
665 used = ((egg_toolbars_model_get_name_flags (etoolbar->priv->model, name) & EGG_TB_MODEL_NAME_USED) != 0);
669 /* If we just want a highlight item, then . */
670 if (etoolbar->priv->dnd_pending > 0)
672 etoolbar->priv->dnd_pending--;
674 if (name != NULL && etoolbar->priv->dnd_toolbar == toolbar && !used)
676 etoolbar->priv->dnd_toolitem = create_item_from_action (etoolbar, name);
677 gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar,
678 etoolbar->priv->dnd_toolitem, ipos);
683 gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
684 etoolbar->priv->dnd_toolbar = NULL;
685 etoolbar->priv->dnd_toolitem = NULL;
687 /* If we don't have a name to use yet, try to create one. */
688 if (name == NULL && gtk_selection_data_get_length (selection_data) >= 0)
690 name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, TRUE);
693 if (name != NULL && !used)
695 gint tpos = get_toolbar_position (etoolbar, GTK_WIDGET (toolbar));
696 egg_toolbars_model_add_item (etoolbar->priv->model, tpos, ipos, name);
697 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
701 gtk_drag_finish (context, FALSE, context->action == GDK_ACTION_MOVE, time);
709 toolbar_drag_drop_cb (GtkToolbar *toolbar,
710 GdkDragContext *context,
714 EggEditableToolbar *etoolbar)
718 target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL);
719 if (target != GDK_NONE)
721 gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
729 toolbar_drag_motion_cb (GtkToolbar *toolbar,
730 GdkDragContext *context,
734 EggEditableToolbar *etoolbar)
736 GdkAtom target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL);
737 if (target == GDK_NONE)
739 gdk_drag_status (context, 0, time);
743 /* Make ourselves the current dnd toolbar, and request a highlight item. */
744 if (etoolbar->priv->dnd_toolbar != toolbar)
746 etoolbar->priv->dnd_toolbar = toolbar;
747 etoolbar->priv->dnd_toolitem = NULL;
748 etoolbar->priv->dnd_pending++;
749 gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
752 /* If a highlight item is available, use it. */
753 else if (etoolbar->priv->dnd_toolitem)
755 gint ipos = gtk_toolbar_get_drop_index (etoolbar->priv->dnd_toolbar, x, y);
756 gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar,
757 etoolbar->priv->dnd_toolitem, ipos);
760 gdk_drag_status (context, context->suggested_action, time);
766 toolbar_drag_leave_cb (GtkToolbar *toolbar,
767 GdkDragContext *context,
769 EggEditableToolbar *etoolbar)
771 gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
773 /* If we were the current dnd toolbar target, remove the item. */
774 if (etoolbar->priv->dnd_toolbar == toolbar)
776 etoolbar->priv->dnd_toolbar = NULL;
777 etoolbar->priv->dnd_toolitem = NULL;
782 configure_drag_dest (EggEditableToolbar *etoolbar,
785 EggToolbarsItemType *type;
786 GtkTargetList *targets;
789 /* Make every toolbar able to receive drag-drops. */
790 gtk_drag_dest_set (GTK_WIDGET (toolbar), 0,
791 dest_drag_types, G_N_ELEMENTS (dest_drag_types),
792 GDK_ACTION_MOVE | GDK_ACTION_COPY);
794 /* Add any specialist drag-drop abilities. */
795 targets = gtk_drag_dest_get_target_list (GTK_WIDGET (toolbar));
796 list = egg_toolbars_model_get_types (etoolbar->priv->model);
800 if (type->new_name != NULL || type->get_name != NULL)
801 gtk_target_list_add (targets, type->type, 0, 0);
807 toggled_visibility_cb (GtkToggleAction *action,
808 EggEditableToolbar *etoolbar)
810 EggEditableToolbarPrivate *priv = etoolbar->priv;
812 EggTbModelFlags flags;
816 visible = gtk_toggle_action_get_active (action);
817 for (i = 0; i < priv->visibility_actions->len; i++)
818 if (g_ptr_array_index (priv->visibility_actions, i) == action)
821 g_return_if_fail (i < priv->visibility_actions->len);
823 dock = get_dock_nth (etoolbar, i);
826 gtk_widget_show (dock);
830 gtk_widget_hide (dock);
833 if (priv->save_hidden)
835 flags = egg_toolbars_model_get_flags (priv->model, i);
839 flags &= ~(EGG_TB_MODEL_HIDDEN);
843 flags |= (EGG_TB_MODEL_HIDDEN);
846 egg_toolbars_model_set_flags (priv->model, i, flags);
851 toolbar_visibility_refresh (EggEditableToolbar *etoolbar)
853 EggEditableToolbarPrivate *priv = etoolbar->priv;
854 gint n_toolbars, n_items, i, j, k;
855 GtkToggleAction *action;
859 char action_name[40];
863 if (priv == NULL || priv->model == NULL || priv->manager == NULL ||
864 priv->visibility_paths == NULL || priv->actions == NULL)
869 if (priv->visibility_actions == NULL)
871 priv->visibility_actions = g_ptr_array_new ();
874 if (priv->visibility_id != 0)
876 gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
879 priv->visibility_id = gtk_ui_manager_new_merge_id (priv->manager);
881 #if GTK_CHECK_VERSION(2,20,0)
882 showing = gtk_widget_get_visible (GTK_WIDGET (etoolbar));
884 showing = GTK_WIDGET_VISIBLE (etoolbar);
887 n_toolbars = egg_toolbars_model_n_toolbars (priv->model);
888 for (i = 0; i < n_toolbars; i++)
890 string = g_string_sized_new (0);
891 n_items = egg_toolbars_model_n_items (priv->model, i);
892 for (k = 0, j = 0; j < n_items; j++)
894 GValue value = { 0, };
898 name = egg_toolbars_model_item_nth (priv->model, i, j);
899 if (name == NULL) continue;
900 action = find_action (etoolbar, name);
901 if (action == NULL) continue;
903 g_value_init (&value, G_TYPE_STRING);
904 g_object_get_property (G_OBJECT (action), "label", &value);
905 name = g_value_get_string (&value);
908 g_value_unset (&value);
911 k += g_utf8_strlen (name, -1) + 2;
914 g_string_append (string, ", ");
917 g_value_unset (&value);
921 g_string_append (string, name);
922 g_value_unset (&value);
926 g_string_append (string, " ...");
929 tmp = g_string_free (string, FALSE);
930 for (j = 0, k = 0; tmp[j]; j++)
932 if (tmp[j] == '_') continue;
937 /* Translaters: This string is for a toggle to display a toolbar.
938 * The name of the toolbar is automatically computed from the widgets
939 * on the toolbar, and is placed at the %s. Note the _ before the %s
940 * which is used to add mnemonics. We know that this is likely to
941 * produce duplicates, but don't worry about it. If your language
942 * normally has a mnemonic at the start, please use the _. If not,
944 action_label = g_strdup_printf (_("Show “_%s”"), tmp);
947 sprintf(action_name, "ToolbarToggle%d", i);
949 if (i >= priv->visibility_actions->len)
951 action = gtk_toggle_action_new (action_name, action_label, NULL, NULL);
952 g_ptr_array_add (priv->visibility_actions, action);
953 g_signal_connect_object (action, "toggled",
954 G_CALLBACK (toggled_visibility_cb),
956 gtk_action_group_add_action (priv->actions, GTK_ACTION (action));
960 action = g_ptr_array_index (priv->visibility_actions, i);
961 g_object_set (action, "label", action_label, NULL);
964 gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i)
965 & EGG_TB_MODEL_NOT_REMOVABLE) == 0);
966 gtk_action_set_sensitive (GTK_ACTION (action), showing);
967 #if GTK_CHECK_VERSION(2,20,0)
968 gtk_toggle_action_set_active (action, gtk_widget_get_visible
969 (get_dock_nth (etoolbar, i)));
971 gtk_toggle_action_set_active (action, GTK_WIDGET_VISIBLE
972 (get_dock_nth (etoolbar, i)));
975 for (list = priv->visibility_paths; list != NULL; list = g_list_next (list))
977 gtk_ui_manager_add_ui (priv->manager, priv->visibility_id,
978 (const char *)list->data, action_name, action_name,
979 GTK_UI_MANAGER_MENUITEM, FALSE);
982 g_free (action_label);
985 gtk_ui_manager_ensure_update (priv->manager);
987 while (i < priv->visibility_actions->len)
989 action = g_ptr_array_index (priv->visibility_actions, i);
990 g_ptr_array_remove_index_fast (priv->visibility_actions, i);
991 gtk_action_group_remove_action (priv->actions, GTK_ACTION (action));
997 create_dock (EggEditableToolbar *etoolbar)
999 GtkWidget *toolbar, *hbox;
1001 hbox = gtk_hbox_new (0, FALSE);
1003 toolbar = gtk_toolbar_new ();
1004 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
1005 gtk_widget_show (toolbar);
1006 gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0);
1008 g_signal_connect (toolbar, "drag_drop",
1009 G_CALLBACK (toolbar_drag_drop_cb), etoolbar);
1010 g_signal_connect (toolbar, "drag_motion",
1011 G_CALLBACK (toolbar_drag_motion_cb), etoolbar);
1012 g_signal_connect (toolbar, "drag_leave",
1013 G_CALLBACK (toolbar_drag_leave_cb), etoolbar);
1015 g_signal_connect (toolbar, "drag_data_received",
1016 G_CALLBACK (toolbar_drag_data_received_cb), etoolbar);
1017 g_signal_connect (toolbar, "popup_context_menu",
1018 G_CALLBACK (popup_context_menu_cb), etoolbar);
1020 configure_drag_dest (etoolbar, GTK_TOOLBAR (toolbar));
1026 set_fixed_style (EggEditableToolbar *t, GtkToolbarStyle style)
1028 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
1029 gtk_toolbar_set_style (GTK_TOOLBAR (t->priv->fixed_toolbar),
1030 style == GTK_TOOLBAR_ICONS ? GTK_TOOLBAR_BOTH_HORIZ : style);
1034 unset_fixed_style (EggEditableToolbar *t)
1036 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
1037 gtk_toolbar_unset_style (GTK_TOOLBAR (t->priv->fixed_toolbar));
1041 toolbar_changed_cb (EggToolbarsModel *model,
1043 EggEditableToolbar *etoolbar)
1046 EggTbModelFlags flags;
1047 GtkToolbarStyle style;
1049 flags = egg_toolbars_model_get_flags (model, position);
1050 toolbar = get_toolbar_nth (etoolbar, position);
1052 if (flags & EGG_TB_MODEL_ICONS)
1054 style = GTK_TOOLBAR_ICONS;
1056 else if (flags & EGG_TB_MODEL_TEXT)
1058 style = GTK_TOOLBAR_TEXT;
1060 else if (flags & EGG_TB_MODEL_BOTH)
1062 style = GTK_TOOLBAR_BOTH;
1064 else if (flags & EGG_TB_MODEL_BOTH_HORIZ)
1066 style = GTK_TOOLBAR_BOTH_HORIZ;
1070 gtk_toolbar_unset_style (GTK_TOOLBAR (toolbar));
1071 if (position == 0 && etoolbar->priv->fixed_toolbar)
1073 unset_fixed_style (etoolbar);
1078 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style);
1079 if (position == 0 && etoolbar->priv->fixed_toolbar)
1081 set_fixed_style (etoolbar, style);
1084 toolbar_visibility_refresh (etoolbar);
1088 unparent_fixed (EggEditableToolbar *etoolbar)
1090 GtkWidget *toolbar, *dock;
1091 g_return_if_fail (GTK_IS_TOOLBAR (etoolbar->priv->fixed_toolbar));
1093 toolbar = etoolbar->priv->fixed_toolbar;
1094 dock = get_dock_nth (etoolbar, 0);
1096 if (dock && gtk_widget_get_parent (toolbar) != NULL)
1098 gtk_container_remove (GTK_CONTAINER (dock), toolbar);
1103 update_fixed (EggEditableToolbar *etoolbar)
1105 GtkWidget *toolbar, *dock;
1106 if (!etoolbar->priv->fixed_toolbar) return;
1108 toolbar = etoolbar->priv->fixed_toolbar;
1109 dock = get_dock_nth (etoolbar, 0);
1111 if (dock && toolbar && gtk_widget_get_parent (toolbar) == NULL)
1113 gtk_box_pack_end (GTK_BOX (dock), toolbar, FALSE, TRUE, 0);
1115 gtk_widget_show (toolbar);
1117 gtk_widget_set_size_request (dock, -1, -1);
1118 gtk_widget_queue_resize_no_redraw (dock);
1123 toolbar_added_cb (EggToolbarsModel *model,
1125 EggEditableToolbar *etoolbar)
1129 dock = create_dock (etoolbar);
1130 if ((egg_toolbars_model_get_flags (model, position) & EGG_TB_MODEL_HIDDEN) == 0)
1131 gtk_widget_show (dock);
1133 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1135 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1137 gtk_box_reorder_child (GTK_BOX (etoolbar), dock, position);
1139 gtk_widget_show_all (dock);
1141 update_fixed (etoolbar);
1143 toolbar_visibility_refresh (etoolbar);
1147 toolbar_removed_cb (EggToolbarsModel *model,
1149 EggEditableToolbar *etoolbar)
1153 if (position == 0 && etoolbar->priv->fixed_toolbar != NULL)
1155 unparent_fixed (etoolbar);
1158 dock = get_dock_nth (etoolbar, position);
1159 gtk_widget_destroy (dock);
1161 update_fixed (etoolbar);
1163 toolbar_visibility_refresh (etoolbar);
1167 item_added_cb (EggToolbarsModel *model,
1170 EggEditableToolbar *etoolbar)
1176 toolbar = get_toolbar_nth (etoolbar, tpos);
1177 item = create_item_from_position (etoolbar, tpos, ipos);
1178 if (item == NULL) return;
1180 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, ipos);
1182 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1183 configure_item_tooltip (item);
1184 configure_item_cursor (item, etoolbar);
1185 configure_item_sensitivity (item, etoolbar);
1187 dock = get_dock_nth (etoolbar, tpos);
1188 gtk_widget_set_size_request (dock, -1, -1);
1189 gtk_widget_queue_resize_no_redraw (dock);
1191 toolbar_visibility_refresh (etoolbar);
1195 item_removed_cb (EggToolbarsModel *model,
1196 int toolbar_position,
1198 EggEditableToolbar *etoolbar)
1200 EggEditableToolbarPrivate *priv = etoolbar->priv;
1205 toolbar = get_toolbar_nth (etoolbar, toolbar_position);
1206 item = GTK_WIDGET (gtk_toolbar_get_nth_item
1207 (GTK_TOOLBAR (toolbar), position));
1208 g_return_if_fail (item != NULL);
1210 if (item == priv->selected)
1215 gtk_container_remove (GTK_CONTAINER (toolbar), item);
1217 toolbar_visibility_refresh (etoolbar);
1221 egg_editable_toolbar_build (EggEditableToolbar *etoolbar)
1223 int i, l, n_items, n_toolbars;
1224 EggToolbarsModel *model = etoolbar->priv->model;
1226 g_return_if_fail (model != NULL);
1227 g_return_if_fail (etoolbar->priv->manager != NULL);
1229 n_toolbars = egg_toolbars_model_n_toolbars (model);
1231 for (i = 0; i < n_toolbars; i++)
1233 GtkWidget *toolbar, *dock;
1235 dock = create_dock (etoolbar);
1236 if ((egg_toolbars_model_get_flags (model, i) & EGG_TB_MODEL_HIDDEN) == 0)
1237 gtk_widget_show (dock);
1238 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1239 toolbar = get_toolbar_nth (etoolbar, i);
1241 n_items = egg_toolbars_model_n_items (model, i);
1242 for (l = 0; l < n_items; l++)
1246 item = create_item_from_position (etoolbar, i, l);
1249 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, l);
1251 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1252 configure_item_tooltip (item);
1253 configure_item_sensitivity (item, etoolbar);
1257 egg_toolbars_model_remove_item (model, i, l);
1265 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1269 update_fixed (etoolbar);
1272 for (i = 0; i < n_toolbars; i ++)
1274 toolbar_changed_cb (model, i, etoolbar);
1279 egg_editable_toolbar_disconnect_model (EggEditableToolbar *toolbar)
1281 EggToolbarsModel *model = toolbar->priv->model;
1283 g_signal_handlers_disconnect_by_func
1284 (model, G_CALLBACK (item_added_cb), toolbar);
1285 g_signal_handlers_disconnect_by_func
1286 (model, G_CALLBACK (item_removed_cb), toolbar);
1287 g_signal_handlers_disconnect_by_func
1288 (model, G_CALLBACK (toolbar_added_cb), toolbar);
1289 g_signal_handlers_disconnect_by_func
1290 (model, G_CALLBACK (toolbar_removed_cb), toolbar);
1291 g_signal_handlers_disconnect_by_func
1292 (model, G_CALLBACK (toolbar_changed_cb), toolbar);
1296 egg_editable_toolbar_deconstruct (EggEditableToolbar *toolbar)
1298 EggToolbarsModel *model = toolbar->priv->model;
1301 g_return_if_fail (model != NULL);
1303 if (toolbar->priv->fixed_toolbar)
1305 unset_fixed_style (toolbar);
1306 unparent_fixed (toolbar);
1309 children = gtk_container_get_children (GTK_CONTAINER (toolbar));
1310 g_list_foreach (children, (GFunc) gtk_widget_destroy, NULL);
1311 g_list_free (children);
1315 egg_editable_toolbar_set_model (EggEditableToolbar *etoolbar,
1316 EggToolbarsModel *model)
1318 EggEditableToolbarPrivate *priv = etoolbar->priv;
1320 if (priv->model == model) return;
1324 egg_editable_toolbar_disconnect_model (etoolbar);
1325 egg_editable_toolbar_deconstruct (etoolbar);
1327 g_object_unref (priv->model);
1330 priv->model = g_object_ref (model);
1332 egg_editable_toolbar_build (etoolbar);
1334 toolbar_visibility_refresh (etoolbar);
1336 g_signal_connect (model, "item_added",
1337 G_CALLBACK (item_added_cb), etoolbar);
1338 g_signal_connect (model, "item_removed",
1339 G_CALLBACK (item_removed_cb), etoolbar);
1340 g_signal_connect (model, "toolbar_added",
1341 G_CALLBACK (toolbar_added_cb), etoolbar);
1342 g_signal_connect (model, "toolbar_removed",
1343 G_CALLBACK (toolbar_removed_cb), etoolbar);
1344 g_signal_connect (model, "toolbar_changed",
1345 G_CALLBACK (toolbar_changed_cb), etoolbar);
1349 egg_editable_toolbar_init (EggEditableToolbar *etoolbar)
1351 EggEditableToolbarPrivate *priv;
1353 priv = etoolbar->priv = EGG_EDITABLE_TOOLBAR_GET_PRIVATE (etoolbar);
1355 priv->save_hidden = TRUE;
1357 g_signal_connect (etoolbar, "notify::visible",
1358 G_CALLBACK (toolbar_visibility_refresh), NULL);
1362 egg_editable_toolbar_dispose (GObject *object)
1364 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1365 EggEditableToolbarPrivate *priv = etoolbar->priv;
1368 if (priv->fixed_toolbar != NULL)
1370 g_object_unref (priv->fixed_toolbar);
1371 priv->fixed_toolbar = NULL;
1374 if (priv->visibility_paths)
1376 children = priv->visibility_paths;
1377 g_list_foreach (children, (GFunc) g_free, NULL);
1378 g_list_free (children);
1379 priv->visibility_paths = NULL;
1382 g_free (priv->popup_path);
1383 priv->popup_path = NULL;
1385 if (priv->manager != NULL)
1387 if (priv->visibility_id)
1389 gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
1390 priv->visibility_id = 0;
1393 g_object_unref (priv->manager);
1394 priv->manager = NULL;
1399 egg_editable_toolbar_disconnect_model (etoolbar);
1400 g_object_unref (priv->model);
1404 G_OBJECT_CLASS (egg_editable_toolbar_parent_class)->dispose (object);
1408 egg_editable_toolbar_set_ui_manager (EggEditableToolbar *etoolbar,
1409 GtkUIManager *manager)
1411 static const GtkActionEntry actions[] = {
1412 { "MoveToolItem", STOCK_DRAG_MODE, N_("_Move on Toolbar"), NULL,
1413 N_("Move the selected item on the toolbar"), G_CALLBACK (move_item_cb) },
1414 { "RemoveToolItem", GTK_STOCK_REMOVE, N_("_Remove from Toolbar"), NULL,
1415 N_("Remove the selected item from the toolbar"), G_CALLBACK (remove_item_cb) },
1416 { "RemoveToolbar", GTK_STOCK_DELETE, N_("_Delete Toolbar"), NULL,
1417 N_("Remove the selected toolbar"), G_CALLBACK (remove_toolbar_cb) },
1420 etoolbar->priv->manager = g_object_ref (manager);
1422 etoolbar->priv->actions = gtk_action_group_new ("ToolbarActions");
1423 gtk_action_group_set_translation_domain (etoolbar->priv->actions, GETTEXT_PACKAGE);
1424 gtk_action_group_add_actions (etoolbar->priv->actions, actions,
1425 G_N_ELEMENTS (actions), etoolbar);
1426 gtk_ui_manager_insert_action_group (manager, etoolbar->priv->actions, -1);
1427 g_object_unref (etoolbar->priv->actions);
1429 toolbar_visibility_refresh (etoolbar);
1432 GtkWidget * egg_editable_toolbar_get_selected (EggEditableToolbar *etoolbar)
1434 return etoolbar->priv->selected;
1438 egg_editable_toolbar_set_selected (EggEditableToolbar *etoolbar,
1441 GtkWidget *toolbar, *toolitem;
1444 etoolbar->priv->selected = widget;
1446 toolbar = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR) : NULL;
1447 toolitem = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM) : NULL;
1451 gint tpos = get_toolbar_position (etoolbar, toolbar);
1452 editable = ((egg_toolbars_model_get_flags (etoolbar->priv->model, tpos) & EGG_TB_MODEL_NOT_EDITABLE) == 0);
1459 gtk_action_set_visible (find_action (etoolbar, "RemoveToolbar"), (toolbar != NULL) && (etoolbar->priv->edit_mode > 0));
1460 gtk_action_set_visible (find_action (etoolbar, "RemoveToolItem"), (toolitem != NULL) && editable);
1461 gtk_action_set_visible (find_action (etoolbar, "MoveToolItem"), (toolitem != NULL) && editable);
1465 set_edit_mode (EggEditableToolbar *etoolbar,
1468 EggEditableToolbarPrivate *priv = etoolbar->priv;
1471 i = priv->edit_mode;
1478 g_return_if_fail (priv->edit_mode > 0);
1481 i *= priv->edit_mode;
1485 for (i = get_n_toolbars (etoolbar)-1; i >= 0; i--)
1489 toolbar = get_toolbar_nth (etoolbar, i);
1490 n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
1492 if (n_items == 0 && priv->edit_mode == 0)
1494 egg_toolbars_model_remove_toolbar (priv->model, i);
1498 for (l = 0; l < n_items; l++)
1502 item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
1504 configure_item_cursor (item, etoolbar);
1505 configure_item_sensitivity (item, etoolbar);
1513 egg_editable_toolbar_set_property (GObject *object,
1515 const GValue *value,
1518 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1522 case PROP_UI_MANAGER:
1523 egg_editable_toolbar_set_ui_manager (etoolbar, g_value_get_object (value));
1525 case PROP_TOOLBARS_MODEL:
1526 egg_editable_toolbar_set_model (etoolbar, g_value_get_object (value));
1529 egg_editable_toolbar_set_selected (etoolbar, g_value_get_object (value));
1531 case PROP_POPUP_PATH:
1532 etoolbar->priv->popup_path = g_strdup (g_value_get_string (value));
1534 case PROP_EDIT_MODE:
1535 set_edit_mode (etoolbar, g_value_get_boolean (value));
1538 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1544 egg_editable_toolbar_get_property (GObject *object,
1549 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1553 case PROP_UI_MANAGER:
1554 g_value_set_object (value, etoolbar->priv->manager);
1556 case PROP_TOOLBARS_MODEL:
1557 g_value_set_object (value, etoolbar->priv->model);
1560 g_value_set_object (value, etoolbar->priv->selected);
1562 case PROP_EDIT_MODE:
1563 g_value_set_boolean (value, etoolbar->priv->edit_mode>0);
1566 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1572 egg_editable_toolbar_class_init (EggEditableToolbarClass *klass)
1574 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1576 object_class->dispose = egg_editable_toolbar_dispose;
1577 object_class->set_property = egg_editable_toolbar_set_property;
1578 object_class->get_property = egg_editable_toolbar_get_property;
1580 egg_editable_toolbar_signals[ACTION_REQUEST] =
1581 g_signal_new ("action_request",
1582 G_OBJECT_CLASS_TYPE (object_class),
1584 G_STRUCT_OFFSET (EggEditableToolbarClass, action_request),
1585 NULL, NULL, g_cclosure_marshal_VOID__STRING,
1586 G_TYPE_NONE, 1, G_TYPE_STRING);
1588 g_object_class_install_property (object_class,
1590 g_param_spec_object ("ui-manager",
1593 GTK_TYPE_UI_MANAGER,
1594 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1595 g_object_class_install_property (object_class,
1596 PROP_TOOLBARS_MODEL,
1597 g_param_spec_object ("model",
1600 EGG_TYPE_TOOLBARS_MODEL,
1601 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1602 g_object_class_install_property (object_class,
1604 g_param_spec_object ("selected",
1606 "Selected toolitem",
1608 G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1610 g_object_class_install_property (object_class,
1612 g_param_spec_string ("popup-path",
1616 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1618 g_object_class_install_property (object_class,
1620 g_param_spec_boolean ("edit-mode",
1624 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1626 g_type_class_add_private (object_class, sizeof (EggEditableToolbarPrivate));
1630 egg_editable_toolbar_new (GtkUIManager *manager,
1631 const char *popup_path)
1633 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1634 "ui-manager", manager,
1635 "popup-path", popup_path,
1640 egg_editable_toolbar_new_with_model (GtkUIManager *manager,
1641 EggToolbarsModel *model,
1642 const char *popup_path)
1644 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1645 "ui-manager", manager,
1647 "popup-path", popup_path,
1652 egg_editable_toolbar_get_edit_mode (EggEditableToolbar *etoolbar)
1654 EggEditableToolbarPrivate *priv = etoolbar->priv;
1656 return priv->edit_mode > 0;
1660 egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar,
1663 set_edit_mode (etoolbar, mode);
1664 g_object_notify (G_OBJECT (etoolbar), "edit-mode");
1668 egg_editable_toolbar_add_visibility (EggEditableToolbar *etoolbar,
1671 etoolbar->priv->visibility_paths = g_list_prepend
1672 (etoolbar->priv->visibility_paths, g_strdup (path));
1676 egg_editable_toolbar_show (EggEditableToolbar *etoolbar,
1679 EggEditableToolbarPrivate *priv = etoolbar->priv;
1680 EggToolbarsModel *model = priv->model;
1683 n_toolbars = egg_toolbars_model_n_toolbars (model);
1684 for (i = 0; i < n_toolbars; i++)
1686 const char *toolbar_name;
1688 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1689 if (strcmp (toolbar_name, name) == 0)
1691 gtk_widget_show (get_dock_nth (etoolbar, i));
1697 egg_editable_toolbar_hide (EggEditableToolbar *etoolbar,
1700 EggEditableToolbarPrivate *priv = etoolbar->priv;
1701 EggToolbarsModel *model = priv->model;
1704 n_toolbars = egg_toolbars_model_n_toolbars (model);
1705 for (i = 0; i < n_toolbars; i++)
1707 const char *toolbar_name;
1709 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1710 if (strcmp (toolbar_name, name) == 0)
1712 gtk_widget_hide (get_dock_nth (etoolbar, i));
1718 egg_editable_toolbar_set_fixed (EggEditableToolbar *etoolbar,
1719 GtkToolbar *toolbar)
1721 EggEditableToolbarPrivate *priv = etoolbar->priv;
1723 g_return_if_fail (!toolbar || GTK_IS_TOOLBAR (toolbar));
1725 if (priv->fixed_toolbar)
1727 unparent_fixed (etoolbar);
1728 g_object_unref (priv->fixed_toolbar);
1729 priv->fixed_toolbar = NULL;
1734 priv->fixed_toolbar = GTK_WIDGET (toolbar);
1735 gtk_toolbar_set_show_arrow (toolbar, FALSE);
1736 g_object_ref_sink (toolbar);
1739 update_fixed (etoolbar);
1742 #define DEFAULT_ICON_HEIGHT 20
1744 /* We should probably experiment some more with this.
1745 * Right now the rendered icon is pretty good for most
1746 * themes. However, the icon is slightly large for themes
1747 * with large toolbar icons.
1750 new_pixbuf_from_widget (GtkWidget *widget)
1757 screen = gtk_widget_get_screen (widget);
1759 if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen),
1760 GTK_ICON_SIZE_LARGE_TOOLBAR,
1764 icon_height = DEFAULT_ICON_HEIGHT;
1767 window = gtk_offscreen_window_new ();
1768 /* Set the width to -1 as we want the separator to be as thin as possible. */
1769 gtk_widget_set_size_request (widget, -1, icon_height);
1771 gtk_container_add (GTK_CONTAINER (window), widget);
1772 gtk_widget_show_all (window);
1774 /* Process the waiting events to have the widget actually drawn */
1775 gdk_window_process_updates (gtk_widget_get_window (window), TRUE);
1776 pixbuf = gtk_offscreen_window_get_pixbuf (GTK_OFFSCREEN_WINDOW (window));
1777 gtk_widget_destroy (window);
1783 new_separator_pixbuf (void)
1785 GtkWidget *separator;
1788 separator = gtk_vseparator_new ();
1789 pixbuf = new_pixbuf_from_widget (separator);
1794 update_separator_image (GtkImage *image)
1796 GdkPixbuf *pixbuf = new_separator_pixbuf ();
1797 gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
1798 g_object_unref (pixbuf);
1802 style_set_cb (GtkWidget *widget,
1803 GtkStyle *previous_style,
1807 update_separator_image (image);
1812 _egg_editable_toolbar_new_separator_image (void)
1814 GtkWidget *image = gtk_image_new ();
1815 update_separator_image (GTK_IMAGE (image));
1816 g_signal_connect (G_OBJECT (image), "style_set",
1817 G_CALLBACK (style_set_cb), GTK_IMAGE (image));
1823 egg_editable_toolbar_get_model (EggEditableToolbar *etoolbar)
1825 return etoolbar->priv->model;