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 g_object_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_pixbuf (widget, stock_id,
491 GTK_ICON_SIZE_LARGE_TOOLBAR);
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,
698 gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
702 gtk_drag_finish (context, FALSE,
703 gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE, time);
711 toolbar_drag_drop_cb (GtkToolbar *toolbar,
712 GdkDragContext *context,
716 EggEditableToolbar *etoolbar)
720 target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL);
721 if (target != GDK_NONE)
723 gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
731 toolbar_drag_motion_cb (GtkToolbar *toolbar,
732 GdkDragContext *context,
736 EggEditableToolbar *etoolbar)
738 GdkAtom target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL);
739 if (target == GDK_NONE)
741 gdk_drag_status (context, 0, time);
745 /* Make ourselves the current dnd toolbar, and request a highlight item. */
746 if (etoolbar->priv->dnd_toolbar != toolbar)
748 etoolbar->priv->dnd_toolbar = toolbar;
749 etoolbar->priv->dnd_toolitem = NULL;
750 etoolbar->priv->dnd_pending++;
751 gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
754 /* If a highlight item is available, use it. */
755 else if (etoolbar->priv->dnd_toolitem)
757 gint ipos = gtk_toolbar_get_drop_index (etoolbar->priv->dnd_toolbar, x, y);
758 gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar,
759 etoolbar->priv->dnd_toolitem, ipos);
762 gdk_drag_status (context, gdk_drag_context_get_suggested_action (context), time);
768 toolbar_drag_leave_cb (GtkToolbar *toolbar,
769 GdkDragContext *context,
771 EggEditableToolbar *etoolbar)
773 gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
775 /* If we were the current dnd toolbar target, remove the item. */
776 if (etoolbar->priv->dnd_toolbar == toolbar)
778 etoolbar->priv->dnd_toolbar = NULL;
779 etoolbar->priv->dnd_toolitem = NULL;
784 configure_drag_dest (EggEditableToolbar *etoolbar,
787 EggToolbarsItemType *type;
788 GtkTargetList *targets;
791 /* Make every toolbar able to receive drag-drops. */
792 gtk_drag_dest_set (GTK_WIDGET (toolbar), 0,
793 dest_drag_types, G_N_ELEMENTS (dest_drag_types),
794 GDK_ACTION_MOVE | GDK_ACTION_COPY);
796 /* Add any specialist drag-drop abilities. */
797 targets = gtk_drag_dest_get_target_list (GTK_WIDGET (toolbar));
798 list = egg_toolbars_model_get_types (etoolbar->priv->model);
802 if (type->new_name != NULL || type->get_name != NULL)
803 gtk_target_list_add (targets, type->type, 0, 0);
809 toggled_visibility_cb (GtkToggleAction *action,
810 EggEditableToolbar *etoolbar)
812 EggEditableToolbarPrivate *priv = etoolbar->priv;
814 EggTbModelFlags flags;
818 visible = gtk_toggle_action_get_active (action);
819 for (i = 0; i < priv->visibility_actions->len; i++)
820 if (g_ptr_array_index (priv->visibility_actions, i) == action)
823 g_return_if_fail (i < priv->visibility_actions->len);
825 dock = get_dock_nth (etoolbar, i);
828 gtk_widget_show (dock);
832 gtk_widget_hide (dock);
835 if (priv->save_hidden)
837 flags = egg_toolbars_model_get_flags (priv->model, i);
841 flags &= ~(EGG_TB_MODEL_HIDDEN);
845 flags |= (EGG_TB_MODEL_HIDDEN);
848 egg_toolbars_model_set_flags (priv->model, i, flags);
853 toolbar_visibility_refresh (EggEditableToolbar *etoolbar)
855 EggEditableToolbarPrivate *priv = etoolbar->priv;
856 gint n_toolbars, n_items, i, j, k;
857 GtkToggleAction *action;
861 char action_name[40];
865 if (priv == NULL || priv->model == NULL || priv->manager == NULL ||
866 priv->visibility_paths == NULL || priv->actions == NULL)
871 if (priv->visibility_actions == NULL)
873 priv->visibility_actions = g_ptr_array_new ();
876 if (priv->visibility_id != 0)
878 gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
881 priv->visibility_id = gtk_ui_manager_new_merge_id (priv->manager);
883 #if GTK_CHECK_VERSION(2,20,0)
884 showing = gtk_widget_get_visible (GTK_WIDGET (etoolbar));
886 showing = GTK_WIDGET_VISIBLE (etoolbar);
889 n_toolbars = egg_toolbars_model_n_toolbars (priv->model);
890 for (i = 0; i < n_toolbars; i++)
892 string = g_string_sized_new (0);
893 n_items = egg_toolbars_model_n_items (priv->model, i);
894 for (k = 0, j = 0; j < n_items; j++)
896 GValue value = { 0, };
900 name = egg_toolbars_model_item_nth (priv->model, i, j);
901 if (name == NULL) continue;
902 action = find_action (etoolbar, name);
903 if (action == NULL) continue;
905 g_value_init (&value, G_TYPE_STRING);
906 g_object_get_property (G_OBJECT (action), "label", &value);
907 name = g_value_get_string (&value);
910 g_value_unset (&value);
913 k += g_utf8_strlen (name, -1) + 2;
916 g_string_append (string, ", ");
919 g_value_unset (&value);
923 g_string_append (string, name);
924 g_value_unset (&value);
928 g_string_append (string, " ...");
931 tmp = g_string_free (string, FALSE);
932 for (j = 0, k = 0; tmp[j]; j++)
934 if (tmp[j] == '_') continue;
939 /* Translaters: This string is for a toggle to display a toolbar.
940 * The name of the toolbar is automatically computed from the widgets
941 * on the toolbar, and is placed at the %s. Note the _ before the %s
942 * which is used to add mnemonics. We know that this is likely to
943 * produce duplicates, but don't worry about it. If your language
944 * normally has a mnemonic at the start, please use the _. If not,
946 action_label = g_strdup_printf (_("Show “_%s”"), tmp);
949 sprintf(action_name, "ToolbarToggle%d", i);
951 if (i >= priv->visibility_actions->len)
953 action = gtk_toggle_action_new (action_name, action_label, NULL, NULL);
954 g_ptr_array_add (priv->visibility_actions, action);
955 g_signal_connect_object (action, "toggled",
956 G_CALLBACK (toggled_visibility_cb),
958 gtk_action_group_add_action (priv->actions, GTK_ACTION (action));
962 action = g_ptr_array_index (priv->visibility_actions, i);
963 g_object_set (action, "label", action_label, NULL);
966 gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i)
967 & EGG_TB_MODEL_NOT_REMOVABLE) == 0);
968 gtk_action_set_sensitive (GTK_ACTION (action), showing);
969 #if GTK_CHECK_VERSION(2,20,0)
970 gtk_toggle_action_set_active (action, gtk_widget_get_visible
971 (get_dock_nth (etoolbar, i)));
973 gtk_toggle_action_set_active (action, GTK_WIDGET_VISIBLE
974 (get_dock_nth (etoolbar, i)));
977 for (list = priv->visibility_paths; list != NULL; list = g_list_next (list))
979 gtk_ui_manager_add_ui (priv->manager, priv->visibility_id,
980 (const char *)list->data, action_name, action_name,
981 GTK_UI_MANAGER_MENUITEM, FALSE);
984 g_free (action_label);
987 gtk_ui_manager_ensure_update (priv->manager);
989 while (i < priv->visibility_actions->len)
991 action = g_ptr_array_index (priv->visibility_actions, i);
992 g_ptr_array_remove_index_fast (priv->visibility_actions, i);
993 gtk_action_group_remove_action (priv->actions, GTK_ACTION (action));
999 create_dock (EggEditableToolbar *etoolbar)
1001 GtkWidget *toolbar, *hbox;
1003 hbox = gtk_hbox_new (0, FALSE);
1005 toolbar = gtk_toolbar_new ();
1006 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
1007 gtk_widget_show (toolbar);
1008 gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0);
1010 g_signal_connect (toolbar, "drag_drop",
1011 G_CALLBACK (toolbar_drag_drop_cb), etoolbar);
1012 g_signal_connect (toolbar, "drag_motion",
1013 G_CALLBACK (toolbar_drag_motion_cb), etoolbar);
1014 g_signal_connect (toolbar, "drag_leave",
1015 G_CALLBACK (toolbar_drag_leave_cb), etoolbar);
1017 g_signal_connect (toolbar, "drag_data_received",
1018 G_CALLBACK (toolbar_drag_data_received_cb), etoolbar);
1019 g_signal_connect (toolbar, "popup_context_menu",
1020 G_CALLBACK (popup_context_menu_cb), etoolbar);
1022 configure_drag_dest (etoolbar, GTK_TOOLBAR (toolbar));
1028 set_fixed_style (EggEditableToolbar *t, GtkToolbarStyle style)
1030 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
1031 gtk_toolbar_set_style (GTK_TOOLBAR (t->priv->fixed_toolbar),
1032 style == GTK_TOOLBAR_ICONS ? GTK_TOOLBAR_BOTH_HORIZ : style);
1036 unset_fixed_style (EggEditableToolbar *t)
1038 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
1039 gtk_toolbar_unset_style (GTK_TOOLBAR (t->priv->fixed_toolbar));
1043 toolbar_changed_cb (EggToolbarsModel *model,
1045 EggEditableToolbar *etoolbar)
1048 EggTbModelFlags flags;
1049 GtkToolbarStyle style;
1051 flags = egg_toolbars_model_get_flags (model, position);
1052 toolbar = get_toolbar_nth (etoolbar, position);
1054 if (flags & EGG_TB_MODEL_ICONS)
1056 style = GTK_TOOLBAR_ICONS;
1058 else if (flags & EGG_TB_MODEL_TEXT)
1060 style = GTK_TOOLBAR_TEXT;
1062 else if (flags & EGG_TB_MODEL_BOTH)
1064 style = GTK_TOOLBAR_BOTH;
1066 else if (flags & EGG_TB_MODEL_BOTH_HORIZ)
1068 style = GTK_TOOLBAR_BOTH_HORIZ;
1072 gtk_toolbar_unset_style (GTK_TOOLBAR (toolbar));
1073 if (position == 0 && etoolbar->priv->fixed_toolbar)
1075 unset_fixed_style (etoolbar);
1080 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style);
1081 if (position == 0 && etoolbar->priv->fixed_toolbar)
1083 set_fixed_style (etoolbar, style);
1086 toolbar_visibility_refresh (etoolbar);
1090 unparent_fixed (EggEditableToolbar *etoolbar)
1092 GtkWidget *toolbar, *dock;
1093 g_return_if_fail (GTK_IS_TOOLBAR (etoolbar->priv->fixed_toolbar));
1095 toolbar = etoolbar->priv->fixed_toolbar;
1096 dock = get_dock_nth (etoolbar, 0);
1098 if (dock && gtk_widget_get_parent (toolbar) != NULL)
1100 gtk_container_remove (GTK_CONTAINER (dock), toolbar);
1105 update_fixed (EggEditableToolbar *etoolbar)
1107 GtkWidget *toolbar, *dock;
1108 if (!etoolbar->priv->fixed_toolbar) return;
1110 toolbar = etoolbar->priv->fixed_toolbar;
1111 dock = get_dock_nth (etoolbar, 0);
1113 if (dock && toolbar && gtk_widget_get_parent (toolbar) == NULL)
1115 gtk_box_pack_end (GTK_BOX (dock), toolbar, FALSE, TRUE, 0);
1117 gtk_widget_show (toolbar);
1119 gtk_widget_set_size_request (dock, -1, -1);
1120 gtk_widget_queue_resize_no_redraw (dock);
1125 toolbar_added_cb (EggToolbarsModel *model,
1127 EggEditableToolbar *etoolbar)
1131 dock = create_dock (etoolbar);
1132 if ((egg_toolbars_model_get_flags (model, position) & EGG_TB_MODEL_HIDDEN) == 0)
1133 gtk_widget_show (dock);
1135 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1137 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1139 gtk_box_reorder_child (GTK_BOX (etoolbar), dock, position);
1141 gtk_widget_show_all (dock);
1143 update_fixed (etoolbar);
1145 toolbar_visibility_refresh (etoolbar);
1149 toolbar_removed_cb (EggToolbarsModel *model,
1151 EggEditableToolbar *etoolbar)
1155 if (position == 0 && etoolbar->priv->fixed_toolbar != NULL)
1157 unparent_fixed (etoolbar);
1160 dock = get_dock_nth (etoolbar, position);
1161 gtk_widget_destroy (dock);
1163 update_fixed (etoolbar);
1165 toolbar_visibility_refresh (etoolbar);
1169 item_added_cb (EggToolbarsModel *model,
1172 EggEditableToolbar *etoolbar)
1178 toolbar = get_toolbar_nth (etoolbar, tpos);
1179 item = create_item_from_position (etoolbar, tpos, ipos);
1180 if (item == NULL) return;
1182 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, ipos);
1184 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1185 configure_item_tooltip (item);
1186 configure_item_cursor (item, etoolbar);
1187 configure_item_sensitivity (item, etoolbar);
1189 dock = get_dock_nth (etoolbar, tpos);
1190 gtk_widget_set_size_request (dock, -1, -1);
1191 gtk_widget_queue_resize_no_redraw (dock);
1193 toolbar_visibility_refresh (etoolbar);
1197 item_removed_cb (EggToolbarsModel *model,
1198 int toolbar_position,
1200 EggEditableToolbar *etoolbar)
1202 EggEditableToolbarPrivate *priv = etoolbar->priv;
1207 toolbar = get_toolbar_nth (etoolbar, toolbar_position);
1208 item = GTK_WIDGET (gtk_toolbar_get_nth_item
1209 (GTK_TOOLBAR (toolbar), position));
1210 g_return_if_fail (item != NULL);
1212 if (item == priv->selected)
1217 gtk_container_remove (GTK_CONTAINER (toolbar), item);
1219 toolbar_visibility_refresh (etoolbar);
1223 egg_editable_toolbar_build (EggEditableToolbar *etoolbar)
1225 int i, l, n_items, n_toolbars;
1226 EggToolbarsModel *model = etoolbar->priv->model;
1228 g_return_if_fail (model != NULL);
1229 g_return_if_fail (etoolbar->priv->manager != NULL);
1231 n_toolbars = egg_toolbars_model_n_toolbars (model);
1233 for (i = 0; i < n_toolbars; i++)
1235 GtkWidget *toolbar, *dock;
1237 dock = create_dock (etoolbar);
1238 if ((egg_toolbars_model_get_flags (model, i) & EGG_TB_MODEL_HIDDEN) == 0)
1239 gtk_widget_show (dock);
1240 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1241 toolbar = get_toolbar_nth (etoolbar, i);
1243 n_items = egg_toolbars_model_n_items (model, i);
1244 for (l = 0; l < n_items; l++)
1248 item = create_item_from_position (etoolbar, i, l);
1251 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, l);
1253 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1254 configure_item_tooltip (item);
1255 configure_item_sensitivity (item, etoolbar);
1259 egg_toolbars_model_remove_item (model, i, l);
1267 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1271 update_fixed (etoolbar);
1274 for (i = 0; i < n_toolbars; i ++)
1276 toolbar_changed_cb (model, i, etoolbar);
1281 egg_editable_toolbar_disconnect_model (EggEditableToolbar *toolbar)
1283 EggToolbarsModel *model = toolbar->priv->model;
1285 g_signal_handlers_disconnect_by_func
1286 (model, G_CALLBACK (item_added_cb), toolbar);
1287 g_signal_handlers_disconnect_by_func
1288 (model, G_CALLBACK (item_removed_cb), toolbar);
1289 g_signal_handlers_disconnect_by_func
1290 (model, G_CALLBACK (toolbar_added_cb), toolbar);
1291 g_signal_handlers_disconnect_by_func
1292 (model, G_CALLBACK (toolbar_removed_cb), toolbar);
1293 g_signal_handlers_disconnect_by_func
1294 (model, G_CALLBACK (toolbar_changed_cb), toolbar);
1298 egg_editable_toolbar_deconstruct (EggEditableToolbar *toolbar)
1300 EggToolbarsModel *model = toolbar->priv->model;
1303 g_return_if_fail (model != NULL);
1305 if (toolbar->priv->fixed_toolbar)
1307 unset_fixed_style (toolbar);
1308 unparent_fixed (toolbar);
1311 children = gtk_container_get_children (GTK_CONTAINER (toolbar));
1312 g_list_foreach (children, (GFunc) gtk_widget_destroy, NULL);
1313 g_list_free (children);
1317 egg_editable_toolbar_set_model (EggEditableToolbar *etoolbar,
1318 EggToolbarsModel *model)
1320 EggEditableToolbarPrivate *priv = etoolbar->priv;
1322 if (priv->model == model) return;
1326 egg_editable_toolbar_disconnect_model (etoolbar);
1327 egg_editable_toolbar_deconstruct (etoolbar);
1329 g_object_unref (priv->model);
1332 priv->model = g_object_ref (model);
1334 egg_editable_toolbar_build (etoolbar);
1336 toolbar_visibility_refresh (etoolbar);
1338 g_signal_connect (model, "item_added",
1339 G_CALLBACK (item_added_cb), etoolbar);
1340 g_signal_connect (model, "item_removed",
1341 G_CALLBACK (item_removed_cb), etoolbar);
1342 g_signal_connect (model, "toolbar_added",
1343 G_CALLBACK (toolbar_added_cb), etoolbar);
1344 g_signal_connect (model, "toolbar_removed",
1345 G_CALLBACK (toolbar_removed_cb), etoolbar);
1346 g_signal_connect (model, "toolbar_changed",
1347 G_CALLBACK (toolbar_changed_cb), etoolbar);
1351 egg_editable_toolbar_init (EggEditableToolbar *etoolbar)
1353 EggEditableToolbarPrivate *priv;
1355 priv = etoolbar->priv = EGG_EDITABLE_TOOLBAR_GET_PRIVATE (etoolbar);
1357 priv->save_hidden = TRUE;
1359 g_signal_connect (etoolbar, "notify::visible",
1360 G_CALLBACK (toolbar_visibility_refresh), NULL);
1364 egg_editable_toolbar_dispose (GObject *object)
1366 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1367 EggEditableToolbarPrivate *priv = etoolbar->priv;
1370 if (priv->fixed_toolbar != NULL)
1372 g_object_unref (priv->fixed_toolbar);
1373 priv->fixed_toolbar = NULL;
1376 if (priv->visibility_paths)
1378 children = priv->visibility_paths;
1379 g_list_foreach (children, (GFunc) g_free, NULL);
1380 g_list_free (children);
1381 priv->visibility_paths = NULL;
1384 g_free (priv->popup_path);
1385 priv->popup_path = NULL;
1387 if (priv->manager != NULL)
1389 if (priv->visibility_id)
1391 gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
1392 priv->visibility_id = 0;
1395 g_object_unref (priv->manager);
1396 priv->manager = NULL;
1401 egg_editable_toolbar_disconnect_model (etoolbar);
1402 g_object_unref (priv->model);
1406 G_OBJECT_CLASS (egg_editable_toolbar_parent_class)->dispose (object);
1410 egg_editable_toolbar_set_ui_manager (EggEditableToolbar *etoolbar,
1411 GtkUIManager *manager)
1413 static const GtkActionEntry actions[] = {
1414 { "MoveToolItem", STOCK_DRAG_MODE, N_("_Move on Toolbar"), NULL,
1415 N_("Move the selected item on the toolbar"), G_CALLBACK (move_item_cb) },
1416 { "RemoveToolItem", GTK_STOCK_REMOVE, N_("_Remove from Toolbar"), NULL,
1417 N_("Remove the selected item from the toolbar"), G_CALLBACK (remove_item_cb) },
1418 { "RemoveToolbar", GTK_STOCK_DELETE, N_("_Delete Toolbar"), NULL,
1419 N_("Remove the selected toolbar"), G_CALLBACK (remove_toolbar_cb) },
1422 etoolbar->priv->manager = g_object_ref (manager);
1424 etoolbar->priv->actions = gtk_action_group_new ("ToolbarActions");
1425 gtk_action_group_set_translation_domain (etoolbar->priv->actions, GETTEXT_PACKAGE);
1426 gtk_action_group_add_actions (etoolbar->priv->actions, actions,
1427 G_N_ELEMENTS (actions), etoolbar);
1428 gtk_ui_manager_insert_action_group (manager, etoolbar->priv->actions, -1);
1429 g_object_unref (etoolbar->priv->actions);
1431 toolbar_visibility_refresh (etoolbar);
1434 GtkWidget * egg_editable_toolbar_get_selected (EggEditableToolbar *etoolbar)
1436 return etoolbar->priv->selected;
1440 egg_editable_toolbar_set_selected (EggEditableToolbar *etoolbar,
1443 GtkWidget *toolbar, *toolitem;
1446 etoolbar->priv->selected = widget;
1448 toolbar = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR) : NULL;
1449 toolitem = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM) : NULL;
1453 gint tpos = get_toolbar_position (etoolbar, toolbar);
1454 editable = ((egg_toolbars_model_get_flags (etoolbar->priv->model, tpos) & EGG_TB_MODEL_NOT_EDITABLE) == 0);
1461 gtk_action_set_visible (find_action (etoolbar, "RemoveToolbar"), (toolbar != NULL) && (etoolbar->priv->edit_mode > 0));
1462 gtk_action_set_visible (find_action (etoolbar, "RemoveToolItem"), (toolitem != NULL) && editable);
1463 gtk_action_set_visible (find_action (etoolbar, "MoveToolItem"), (toolitem != NULL) && editable);
1467 set_edit_mode (EggEditableToolbar *etoolbar,
1470 EggEditableToolbarPrivate *priv = etoolbar->priv;
1473 i = priv->edit_mode;
1480 g_return_if_fail (priv->edit_mode > 0);
1483 i *= priv->edit_mode;
1487 for (i = get_n_toolbars (etoolbar)-1; i >= 0; i--)
1491 toolbar = get_toolbar_nth (etoolbar, i);
1492 n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
1494 if (n_items == 0 && priv->edit_mode == 0)
1496 egg_toolbars_model_remove_toolbar (priv->model, i);
1500 for (l = 0; l < n_items; l++)
1504 item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
1506 configure_item_cursor (item, etoolbar);
1507 configure_item_sensitivity (item, etoolbar);
1515 egg_editable_toolbar_set_property (GObject *object,
1517 const GValue *value,
1520 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1524 case PROP_UI_MANAGER:
1525 egg_editable_toolbar_set_ui_manager (etoolbar, g_value_get_object (value));
1527 case PROP_TOOLBARS_MODEL:
1528 egg_editable_toolbar_set_model (etoolbar, g_value_get_object (value));
1531 egg_editable_toolbar_set_selected (etoolbar, g_value_get_object (value));
1533 case PROP_POPUP_PATH:
1534 etoolbar->priv->popup_path = g_strdup (g_value_get_string (value));
1536 case PROP_EDIT_MODE:
1537 set_edit_mode (etoolbar, g_value_get_boolean (value));
1540 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1546 egg_editable_toolbar_get_property (GObject *object,
1551 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1555 case PROP_UI_MANAGER:
1556 g_value_set_object (value, etoolbar->priv->manager);
1558 case PROP_TOOLBARS_MODEL:
1559 g_value_set_object (value, etoolbar->priv->model);
1562 g_value_set_object (value, etoolbar->priv->selected);
1564 case PROP_EDIT_MODE:
1565 g_value_set_boolean (value, etoolbar->priv->edit_mode>0);
1568 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1574 egg_editable_toolbar_class_init (EggEditableToolbarClass *klass)
1576 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1578 object_class->dispose = egg_editable_toolbar_dispose;
1579 object_class->set_property = egg_editable_toolbar_set_property;
1580 object_class->get_property = egg_editable_toolbar_get_property;
1582 egg_editable_toolbar_signals[ACTION_REQUEST] =
1583 g_signal_new ("action_request",
1584 G_OBJECT_CLASS_TYPE (object_class),
1586 G_STRUCT_OFFSET (EggEditableToolbarClass, action_request),
1587 NULL, NULL, g_cclosure_marshal_VOID__STRING,
1588 G_TYPE_NONE, 1, G_TYPE_STRING);
1590 g_object_class_install_property (object_class,
1592 g_param_spec_object ("ui-manager",
1595 GTK_TYPE_UI_MANAGER,
1596 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1597 g_object_class_install_property (object_class,
1598 PROP_TOOLBARS_MODEL,
1599 g_param_spec_object ("model",
1602 EGG_TYPE_TOOLBARS_MODEL,
1603 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1604 g_object_class_install_property (object_class,
1606 g_param_spec_object ("selected",
1608 "Selected toolitem",
1610 G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1612 g_object_class_install_property (object_class,
1614 g_param_spec_string ("popup-path",
1618 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1620 g_object_class_install_property (object_class,
1622 g_param_spec_boolean ("edit-mode",
1626 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1628 g_type_class_add_private (object_class, sizeof (EggEditableToolbarPrivate));
1632 egg_editable_toolbar_new (GtkUIManager *manager,
1633 const char *popup_path)
1635 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1636 "ui-manager", manager,
1637 "popup-path", popup_path,
1642 egg_editable_toolbar_new_with_model (GtkUIManager *manager,
1643 EggToolbarsModel *model,
1644 const char *popup_path)
1646 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1647 "ui-manager", manager,
1649 "popup-path", popup_path,
1654 egg_editable_toolbar_get_edit_mode (EggEditableToolbar *etoolbar)
1656 EggEditableToolbarPrivate *priv = etoolbar->priv;
1658 return priv->edit_mode > 0;
1662 egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar,
1665 set_edit_mode (etoolbar, mode);
1666 g_object_notify (G_OBJECT (etoolbar), "edit-mode");
1670 egg_editable_toolbar_add_visibility (EggEditableToolbar *etoolbar,
1673 etoolbar->priv->visibility_paths = g_list_prepend
1674 (etoolbar->priv->visibility_paths, g_strdup (path));
1678 egg_editable_toolbar_show (EggEditableToolbar *etoolbar,
1681 EggEditableToolbarPrivate *priv = etoolbar->priv;
1682 EggToolbarsModel *model = priv->model;
1685 n_toolbars = egg_toolbars_model_n_toolbars (model);
1686 for (i = 0; i < n_toolbars; i++)
1688 const char *toolbar_name;
1690 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1691 if (strcmp (toolbar_name, name) == 0)
1693 gtk_widget_show (get_dock_nth (etoolbar, i));
1699 egg_editable_toolbar_hide (EggEditableToolbar *etoolbar,
1702 EggEditableToolbarPrivate *priv = etoolbar->priv;
1703 EggToolbarsModel *model = priv->model;
1706 n_toolbars = egg_toolbars_model_n_toolbars (model);
1707 for (i = 0; i < n_toolbars; i++)
1709 const char *toolbar_name;
1711 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1712 if (strcmp (toolbar_name, name) == 0)
1714 gtk_widget_hide (get_dock_nth (etoolbar, i));
1720 egg_editable_toolbar_set_fixed (EggEditableToolbar *etoolbar,
1721 GtkToolbar *toolbar)
1723 EggEditableToolbarPrivate *priv = etoolbar->priv;
1725 g_return_if_fail (!toolbar || GTK_IS_TOOLBAR (toolbar));
1727 if (priv->fixed_toolbar)
1729 unparent_fixed (etoolbar);
1730 g_object_unref (priv->fixed_toolbar);
1731 priv->fixed_toolbar = NULL;
1736 priv->fixed_toolbar = GTK_WIDGET (toolbar);
1737 gtk_toolbar_set_show_arrow (toolbar, FALSE);
1738 g_object_ref_sink (toolbar);
1741 update_fixed (etoolbar);
1744 #define DEFAULT_ICON_HEIGHT 20
1746 /* We should probably experiment some more with this.
1747 * Right now the rendered icon is pretty good for most
1748 * themes. However, the icon is slightly large for themes
1749 * with large toolbar icons.
1752 new_pixbuf_from_widget (GtkWidget *widget)
1759 screen = gtk_widget_get_screen (widget);
1761 if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen),
1762 GTK_ICON_SIZE_LARGE_TOOLBAR,
1766 icon_height = DEFAULT_ICON_HEIGHT;
1769 window = gtk_offscreen_window_new ();
1770 /* Set the width to -1 as we want the separator to be as thin as possible. */
1771 gtk_widget_set_size_request (widget, -1, icon_height);
1773 gtk_container_add (GTK_CONTAINER (window), widget);
1774 gtk_widget_show_all (window);
1776 /* Process the waiting events to have the widget actually drawn */
1777 gdk_window_process_updates (gtk_widget_get_window (window), TRUE);
1778 pixbuf = gtk_offscreen_window_get_pixbuf (GTK_OFFSCREEN_WINDOW (window));
1779 gtk_widget_destroy (window);
1785 new_separator_pixbuf (void)
1787 GtkWidget *separator;
1790 separator = gtk_vseparator_new ();
1791 pixbuf = new_pixbuf_from_widget (separator);
1796 update_separator_image (GtkImage *image)
1798 GdkPixbuf *pixbuf = new_separator_pixbuf ();
1799 gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
1800 g_object_unref (pixbuf);
1804 style_set_cb (GtkWidget *widget,
1805 GtkStyle *previous_style,
1809 update_separator_image (image);
1814 _egg_editable_toolbar_new_separator_image (void)
1816 GtkWidget *image = gtk_image_new ();
1817 update_separator_image (GTK_IMAGE (image));
1818 g_signal_connect (G_OBJECT (image), "style_set",
1819 G_CALLBACK (style_set_cb), GTK_IMAGE (image));
1825 egg_editable_toolbar_get_model (EggEditableToolbar *etoolbar)
1827 return etoolbar->priv->model;