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, toolbar->parent);
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;
181 widget = gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM);
182 g_return_if_fail (widget != NULL);
183 g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
185 pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (widget->parent),
186 GTK_TOOL_ITEM (widget));
187 toolbar_pos = get_toolbar_position (etoolbar, widget->parent);
189 egg_toolbars_model_remove_item (etoolbar->priv->model,
194 drag_begin_cb (GtkWidget *widget,
195 GdkDragContext *context,
196 EggEditableToolbar *etoolbar)
201 gtk_widget_hide (widget);
203 #if GTK_CHECK_VERSION (2, 16, 0)
204 action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
206 action = gtk_widget_get_action (widget);
209 if (action == NULL) return;
211 flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model,
212 gtk_action_get_name (action));
213 if (!(flags & EGG_TB_MODEL_NAME_INFINITE))
215 flags &= ~EGG_TB_MODEL_NAME_USED;
216 egg_toolbars_model_set_name_flags (etoolbar->priv->model,
217 gtk_action_get_name (action),
223 drag_end_cb (GtkWidget *widget,
224 GdkDragContext *context,
225 EggEditableToolbar *etoolbar)
230 if (gtk_widget_get_parent (widget) != NULL)
232 gtk_widget_show (widget);
234 #if GTK_CHECK_VERSION (2, 16, 0)
235 action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
237 action = gtk_widget_get_action (widget);
240 if (action == NULL) return;
242 flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model,
243 gtk_action_get_name (action));
244 if (!(flags & EGG_TB_MODEL_NAME_INFINITE))
246 flags |= EGG_TB_MODEL_NAME_USED;
247 egg_toolbars_model_set_name_flags (etoolbar->priv->model,
248 gtk_action_get_name (action),
255 drag_data_get_cb (GtkWidget *widget,
256 GdkDragContext *context,
257 GtkSelectionData *selection_data,
260 EggEditableToolbar *etoolbar)
262 EggToolbarsModel *model;
266 g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
267 model = egg_editable_toolbar_get_model (etoolbar);
269 name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
272 name = g_object_get_data (G_OBJECT (gtk_widget_get_parent (widget)), EGG_ITEM_NAME);
273 g_return_if_fail (name != NULL);
276 data = egg_toolbars_model_get_data (model, selection_data->target, name);
279 gtk_selection_data_set (selection_data, selection_data->target, 8, (unsigned char *)data, strlen (data));
285 move_item_cb (GtkAction *action,
286 EggEditableToolbar *etoolbar)
288 GtkWidget *toolitem = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM);
289 GtkTargetList *list = gtk_target_list_new (dest_drag_types, G_N_ELEMENTS (dest_drag_types));
291 GdkEvent *realevent = gtk_get_current_event();
292 GdkEventMotion event;
293 event.type = GDK_MOTION_NOTIFY;
294 event.window = realevent->any.window;
295 event.send_event = FALSE;
297 event.time = gdk_event_get_time (realevent);
298 gdk_event_get_state (realevent, &event.state);
299 gdk_event_get_coords (realevent, &event.x, &event.y);
300 gdk_event_get_root_coords (realevent, &event.x_root, &event.y_root);
302 gtk_drag_begin (toolitem, list, GDK_ACTION_MOVE, 1, (GdkEvent *)&event);
303 gtk_target_list_unref (list);
307 remove_item_cb (GtkAction *action,
308 EggEditableToolbar *etoolbar)
310 GtkWidget *toolitem = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM);
311 int pos, toolbar_pos;
313 toolbar_pos = get_toolbar_position (etoolbar, toolitem->parent);
314 pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolitem->parent),
315 GTK_TOOL_ITEM (toolitem));
317 egg_toolbars_model_remove_item (etoolbar->priv->model,
320 if (egg_toolbars_model_n_items (etoolbar->priv->model, toolbar_pos) == 0)
322 egg_toolbars_model_remove_toolbar (etoolbar->priv->model, toolbar_pos);
327 remove_toolbar_cb (GtkAction *action,
328 EggEditableToolbar *etoolbar)
330 GtkWidget *selected = egg_editable_toolbar_get_selected (etoolbar);
331 GtkWidget *toolbar = gtk_widget_get_ancestor (selected, GTK_TYPE_TOOLBAR);
334 toolbar_pos = get_toolbar_position (etoolbar, toolbar);
335 egg_toolbars_model_remove_toolbar (etoolbar->priv->model, toolbar_pos);
339 popup_context_deactivate (GtkMenuShell *menu,
340 EggEditableToolbar *etoolbar)
342 egg_editable_toolbar_set_selected (etoolbar, NULL);
343 g_object_notify (G_OBJECT (etoolbar), "selected");
347 popup_context_menu_cb (GtkWidget *toolbar,
351 EggEditableToolbar *etoolbar)
353 if (etoolbar->priv->popup_path != NULL)
357 egg_editable_toolbar_set_selected (etoolbar, toolbar);
358 g_object_notify (G_OBJECT (etoolbar), "selected");
360 menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
361 etoolbar->priv->popup_path));
362 g_return_if_fail (menu != NULL);
363 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, button_number, gtk_get_current_event_time ());
364 g_signal_connect_object (menu, "selection-done",
365 G_CALLBACK (popup_context_deactivate),
371 button_press_event_cb (GtkWidget *widget,
372 GdkEventButton *event,
373 EggEditableToolbar *etoolbar)
375 if (event->button == 3 && etoolbar->priv->popup_path != NULL)
379 egg_editable_toolbar_set_selected (etoolbar, widget);
380 g_object_notify (G_OBJECT (etoolbar), "selected");
382 menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
383 etoolbar->priv->popup_path));
384 g_return_val_if_fail (menu != NULL, FALSE);
385 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button, event->time);
386 g_signal_connect_object (menu, "selection-done",
387 G_CALLBACK (popup_context_deactivate),
397 configure_item_sensitivity (GtkToolItem *item, EggEditableToolbar *etoolbar)
402 name = g_object_get_data (G_OBJECT (item), EGG_ITEM_NAME);
403 action = name ? find_action (etoolbar, name) : NULL;
407 g_object_notify (G_OBJECT (action), "sensitive");
410 gtk_tool_item_set_use_drag_window (item,
411 (etoolbar->priv->edit_mode > 0) ||
412 GTK_IS_SEPARATOR_TOOL_ITEM (item));
417 configure_item_cursor (GtkToolItem *item,
418 EggEditableToolbar *etoolbar)
420 EggEditableToolbarPrivate *priv = etoolbar->priv;
421 GtkWidget *widget = GTK_WIDGET (item);
423 if (widget->window != NULL)
425 if (priv->edit_mode > 0)
429 GdkPixbuf *pixbuf = NULL;
431 screen = gtk_widget_get_screen (GTK_WIDGET (etoolbar));
433 cursor = gdk_cursor_new_for_display (gdk_screen_get_display (screen),
435 gdk_window_set_cursor (widget->window, cursor);
436 gdk_cursor_unref (cursor);
438 gtk_drag_source_set (widget, GDK_BUTTON1_MASK, dest_drag_types,
439 G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE);
440 if (GTK_IS_SEPARATOR_TOOL_ITEM (item))
442 pixbuf = new_separator_pixbuf ();
446 char *icon_name=NULL;
451 name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
452 action = name ? find_action (etoolbar, name) : NULL;
456 g_object_get (action,
457 "icon-name", &icon_name,
458 "stock-id", &stock_id,
464 GtkIconTheme *icon_theme;
465 GtkSettings *settings;
468 screen = gtk_widget_get_screen (widget);
469 icon_theme = gtk_icon_theme_get_for_screen (screen);
470 settings = gtk_settings_get_for_screen (screen);
472 if (!gtk_icon_size_lookup_for_settings (settings,
473 GTK_ICON_SIZE_LARGE_TOOLBAR,
479 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
480 MIN (width, height), 0, NULL);
484 pixbuf = gtk_widget_render_icon (widget, stock_id,
485 GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
491 if (G_UNLIKELY (!pixbuf))
495 gtk_drag_source_set_icon_pixbuf (widget, pixbuf);
496 g_object_unref (pixbuf);
501 gdk_window_set_cursor (GTK_WIDGET(item)->window, NULL);
508 configure_item_tooltip (GtkToolItem *item)
512 #if GTK_CHECK_VERSION (2, 16, 0)
513 action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (item));
515 action = gtk_widget_get_action (GTK_WIDGET (item));
520 g_object_notify (G_OBJECT (action), "tooltip");
526 connect_widget_signals (GtkWidget *proxy, EggEditableToolbar *etoolbar)
528 if (GTK_IS_CONTAINER (proxy))
530 gtk_container_forall (GTK_CONTAINER (proxy),
531 (GtkCallback) connect_widget_signals,
532 (gpointer) etoolbar);
535 if (GTK_IS_TOOL_ITEM (proxy))
537 g_signal_connect_object (proxy, "drag_begin",
538 G_CALLBACK (drag_begin_cb),
540 g_signal_connect_object (proxy, "drag_end",
541 G_CALLBACK (drag_end_cb),
543 g_signal_connect_object (proxy, "drag_data_get",
544 G_CALLBACK (drag_data_get_cb),
546 g_signal_connect_object (proxy, "drag_data_delete",
547 G_CALLBACK (drag_data_delete_cb),
551 if (GTK_IS_BUTTON (proxy) || GTK_IS_TOOL_ITEM (proxy))
553 g_signal_connect_object (proxy, "button-press-event",
554 G_CALLBACK (button_press_event_cb),
560 action_sensitive_cb (GtkAction *action,
564 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR
565 (gtk_widget_get_ancestor (GTK_WIDGET (item), EGG_TYPE_EDITABLE_TOOLBAR));
567 if (etoolbar->priv->edit_mode > 0)
569 gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
574 create_item_from_action (EggEditableToolbar *etoolbar,
579 g_return_val_if_fail (name != NULL, NULL);
581 if (strcmp (name, "_separator") == 0)
583 item = gtk_separator_tool_item_new ();
587 GtkAction *action = find_action (etoolbar, name);
588 if (action == NULL) return NULL;
590 item = GTK_TOOL_ITEM (gtk_action_create_tool_item (action));
592 /* Normally done on-demand by the GtkUIManager, but no
593 * such demand may have been made yet, so do it ourselves.
595 gtk_action_set_accel_group
596 (action, gtk_ui_manager_get_accel_group(etoolbar->priv->manager));
598 g_signal_connect_object (action, "notify::sensitive",
599 G_CALLBACK (action_sensitive_cb), item, 0);
602 gtk_widget_show (GTK_WIDGET (item));
604 g_object_set_data_full (G_OBJECT (item), EGG_ITEM_NAME,
605 g_strdup (name), g_free);
611 create_item_from_position (EggEditableToolbar *etoolbar,
612 int toolbar_position,
618 name = egg_toolbars_model_item_nth (etoolbar->priv->model, toolbar_position, position);
619 item = create_item_from_action (etoolbar, name);
625 toolbar_drag_data_received_cb (GtkToolbar *toolbar,
626 GdkDragContext *context,
629 GtkSelectionData *selection_data,
632 EggEditableToolbar *etoolbar)
634 /* This function can be called for two reasons
636 * (1) drag_motion() needs an item to pass to
637 * gtk_toolbar_set_drop_highlight_item(). We can
638 * recognize this case by etoolbar->priv->pending being TRUE
639 * We should just create an item and return.
641 * (2) The drag has finished, and drag_drop() wants us to
642 * actually add a new item to the toolbar.
645 GdkAtom type = selection_data->type;
646 const char *data = (char *)selection_data->data;
650 gboolean used = FALSE;
652 /* Find out where the drop is occuring, and the name of what is being dropped. */
653 if (selection_data->length >= 0)
655 ipos = gtk_toolbar_get_drop_index (toolbar, x, y);
656 name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, FALSE);
659 used = ((egg_toolbars_model_get_name_flags (etoolbar->priv->model, name) & EGG_TB_MODEL_NAME_USED) != 0);
663 /* If we just want a highlight item, then . */
664 if (etoolbar->priv->dnd_pending > 0)
666 etoolbar->priv->dnd_pending--;
668 if (name != NULL && etoolbar->priv->dnd_toolbar == toolbar && !used)
670 etoolbar->priv->dnd_toolitem = create_item_from_action (etoolbar, name);
671 gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar,
672 etoolbar->priv->dnd_toolitem, ipos);
677 gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
678 etoolbar->priv->dnd_toolbar = NULL;
679 etoolbar->priv->dnd_toolitem = NULL;
681 /* If we don't have a name to use yet, try to create one. */
682 if (name == NULL && selection_data->length >= 0)
684 name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, TRUE);
687 if (name != NULL && !used)
689 gint tpos = get_toolbar_position (etoolbar, GTK_WIDGET (toolbar));
690 egg_toolbars_model_add_item (etoolbar->priv->model, tpos, ipos, name);
691 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
695 gtk_drag_finish (context, FALSE, context->action == GDK_ACTION_MOVE, time);
703 toolbar_drag_drop_cb (GtkToolbar *toolbar,
704 GdkDragContext *context,
708 EggEditableToolbar *etoolbar)
712 target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL);
713 if (target != GDK_NONE)
715 gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
723 toolbar_drag_motion_cb (GtkToolbar *toolbar,
724 GdkDragContext *context,
728 EggEditableToolbar *etoolbar)
730 GdkAtom target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL);
731 if (target == GDK_NONE)
733 gdk_drag_status (context, 0, time);
737 /* Make ourselves the current dnd toolbar, and request a highlight item. */
738 if (etoolbar->priv->dnd_toolbar != toolbar)
740 etoolbar->priv->dnd_toolbar = toolbar;
741 etoolbar->priv->dnd_toolitem = NULL;
742 etoolbar->priv->dnd_pending++;
743 gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
746 /* If a highlight item is available, use it. */
747 else if (etoolbar->priv->dnd_toolitem)
749 gint ipos = gtk_toolbar_get_drop_index (etoolbar->priv->dnd_toolbar, x, y);
750 gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar,
751 etoolbar->priv->dnd_toolitem, ipos);
754 gdk_drag_status (context, context->suggested_action, time);
760 toolbar_drag_leave_cb (GtkToolbar *toolbar,
761 GdkDragContext *context,
763 EggEditableToolbar *etoolbar)
765 gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
767 /* If we were the current dnd toolbar target, remove the item. */
768 if (etoolbar->priv->dnd_toolbar == toolbar)
770 etoolbar->priv->dnd_toolbar = NULL;
771 etoolbar->priv->dnd_toolitem = NULL;
776 configure_drag_dest (EggEditableToolbar *etoolbar,
779 EggToolbarsItemType *type;
780 GtkTargetList *targets;
783 /* Make every toolbar able to receive drag-drops. */
784 gtk_drag_dest_set (GTK_WIDGET (toolbar), 0,
785 dest_drag_types, G_N_ELEMENTS (dest_drag_types),
786 GDK_ACTION_MOVE | GDK_ACTION_COPY);
788 /* Add any specialist drag-drop abilities. */
789 targets = gtk_drag_dest_get_target_list (GTK_WIDGET (toolbar));
790 list = egg_toolbars_model_get_types (etoolbar->priv->model);
794 if (type->new_name != NULL || type->get_name != NULL)
795 gtk_target_list_add (targets, type->type, 0, 0);
801 toggled_visibility_cb (GtkToggleAction *action,
802 EggEditableToolbar *etoolbar)
804 EggEditableToolbarPrivate *priv = etoolbar->priv;
806 EggTbModelFlags flags;
810 visible = gtk_toggle_action_get_active (action);
811 for (i = 0; i < priv->visibility_actions->len; i++)
812 if (g_ptr_array_index (priv->visibility_actions, i) == action)
815 g_return_if_fail (i < priv->visibility_actions->len);
817 dock = get_dock_nth (etoolbar, i);
820 gtk_widget_show (dock);
824 gtk_widget_hide (dock);
827 if (priv->save_hidden)
829 flags = egg_toolbars_model_get_flags (priv->model, i);
833 flags &= ~(EGG_TB_MODEL_HIDDEN);
837 flags |= (EGG_TB_MODEL_HIDDEN);
840 egg_toolbars_model_set_flags (priv->model, i, flags);
845 toolbar_visibility_refresh (EggEditableToolbar *etoolbar)
847 EggEditableToolbarPrivate *priv = etoolbar->priv;
848 gint n_toolbars, n_items, i, j, k;
849 GtkToggleAction *action;
853 char action_name[40];
857 if (priv == NULL || priv->model == NULL || priv->manager == NULL ||
858 priv->visibility_paths == NULL || priv->actions == NULL)
863 if (priv->visibility_actions == NULL)
865 priv->visibility_actions = g_ptr_array_new ();
868 if (priv->visibility_id != 0)
870 gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
873 priv->visibility_id = gtk_ui_manager_new_merge_id (priv->manager);
875 #if GTK_CHECK_VERSION(2,20,0)
876 showing = gtk_widget_get_visible (etoolbar);
878 showing = GTK_WIDGET_VISIBLE (etoolbar);
881 n_toolbars = egg_toolbars_model_n_toolbars (priv->model);
882 for (i = 0; i < n_toolbars; i++)
884 string = g_string_sized_new (0);
885 n_items = egg_toolbars_model_n_items (priv->model, i);
886 for (k = 0, j = 0; j < n_items; j++)
888 GValue value = { 0, };
892 name = egg_toolbars_model_item_nth (priv->model, i, j);
893 if (name == NULL) continue;
894 action = find_action (etoolbar, name);
895 if (action == NULL) continue;
897 g_value_init (&value, G_TYPE_STRING);
898 g_object_get_property (G_OBJECT (action), "label", &value);
899 name = g_value_get_string (&value);
902 g_value_unset (&value);
905 k += g_utf8_strlen (name, -1) + 2;
908 g_string_append (string, ", ");
911 g_value_unset (&value);
915 g_string_append (string, name);
916 g_value_unset (&value);
920 g_string_append (string, " ...");
923 tmp = g_string_free (string, FALSE);
924 for (j = 0, k = 0; tmp[j]; j++)
926 if (tmp[j] == '_') continue;
931 /* Translaters: This string is for a toggle to display a toolbar.
932 * The name of the toolbar is automatically computed from the widgets
933 * on the toolbar, and is placed at the %s. Note the _ before the %s
934 * which is used to add mnemonics. We know that this is likely to
935 * produce duplicates, but don't worry about it. If your language
936 * normally has a mnemonic at the start, please use the _. If not,
938 action_label = g_strdup_printf (_("Show “_%s”"), tmp);
941 sprintf(action_name, "ToolbarToggle%d", i);
943 if (i >= priv->visibility_actions->len)
945 action = gtk_toggle_action_new (action_name, action_label, NULL, NULL);
946 g_ptr_array_add (priv->visibility_actions, action);
947 g_signal_connect_object (action, "toggled",
948 G_CALLBACK (toggled_visibility_cb),
950 gtk_action_group_add_action (priv->actions, GTK_ACTION (action));
954 action = g_ptr_array_index (priv->visibility_actions, i);
955 g_object_set (action, "label", action_label, NULL);
958 gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i)
959 & EGG_TB_MODEL_NOT_REMOVABLE) == 0);
960 gtk_action_set_sensitive (GTK_ACTION (action), showing);
961 #if GTK_CHECK_VERSION(2,20,0)
962 gtk_toggle_action_set_active (action, gtk_widget_get_visible
963 (get_dock_nth (etoolbar, i)));
965 gtk_toggle_action_set_active (action, GTK_WIDGET_VISIBLE
966 (get_dock_nth (etoolbar, i)));
969 for (list = priv->visibility_paths; list != NULL; list = g_list_next (list))
971 gtk_ui_manager_add_ui (priv->manager, priv->visibility_id,
972 (const char *)list->data, action_name, action_name,
973 GTK_UI_MANAGER_MENUITEM, FALSE);
976 g_free (action_label);
979 gtk_ui_manager_ensure_update (priv->manager);
981 while (i < priv->visibility_actions->len)
983 action = g_ptr_array_index (priv->visibility_actions, i);
984 g_ptr_array_remove_index_fast (priv->visibility_actions, i);
985 gtk_action_group_remove_action (priv->actions, GTK_ACTION (action));
991 create_dock (EggEditableToolbar *etoolbar)
993 GtkWidget *toolbar, *hbox;
995 hbox = gtk_hbox_new (0, FALSE);
997 toolbar = gtk_toolbar_new ();
998 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
999 gtk_widget_show (toolbar);
1000 gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0);
1002 g_signal_connect (toolbar, "drag_drop",
1003 G_CALLBACK (toolbar_drag_drop_cb), etoolbar);
1004 g_signal_connect (toolbar, "drag_motion",
1005 G_CALLBACK (toolbar_drag_motion_cb), etoolbar);
1006 g_signal_connect (toolbar, "drag_leave",
1007 G_CALLBACK (toolbar_drag_leave_cb), etoolbar);
1009 g_signal_connect (toolbar, "drag_data_received",
1010 G_CALLBACK (toolbar_drag_data_received_cb), etoolbar);
1011 g_signal_connect (toolbar, "popup_context_menu",
1012 G_CALLBACK (popup_context_menu_cb), etoolbar);
1014 configure_drag_dest (etoolbar, GTK_TOOLBAR (toolbar));
1020 set_fixed_style (EggEditableToolbar *t, GtkToolbarStyle style)
1022 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
1023 gtk_toolbar_set_style (GTK_TOOLBAR (t->priv->fixed_toolbar),
1024 style == GTK_TOOLBAR_ICONS ? GTK_TOOLBAR_BOTH_HORIZ : style);
1028 unset_fixed_style (EggEditableToolbar *t)
1030 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
1031 gtk_toolbar_unset_style (GTK_TOOLBAR (t->priv->fixed_toolbar));
1035 toolbar_changed_cb (EggToolbarsModel *model,
1037 EggEditableToolbar *etoolbar)
1040 EggTbModelFlags flags;
1041 GtkToolbarStyle style;
1043 flags = egg_toolbars_model_get_flags (model, position);
1044 toolbar = get_toolbar_nth (etoolbar, position);
1046 if (flags & EGG_TB_MODEL_ICONS)
1048 style = GTK_TOOLBAR_ICONS;
1050 else if (flags & EGG_TB_MODEL_TEXT)
1052 style = GTK_TOOLBAR_TEXT;
1054 else if (flags & EGG_TB_MODEL_BOTH)
1056 style = GTK_TOOLBAR_BOTH;
1058 else if (flags & EGG_TB_MODEL_BOTH_HORIZ)
1060 style = GTK_TOOLBAR_BOTH_HORIZ;
1064 gtk_toolbar_unset_style (GTK_TOOLBAR (toolbar));
1065 if (position == 0 && etoolbar->priv->fixed_toolbar)
1067 unset_fixed_style (etoolbar);
1072 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style);
1073 if (position == 0 && etoolbar->priv->fixed_toolbar)
1075 set_fixed_style (etoolbar, style);
1078 toolbar_visibility_refresh (etoolbar);
1082 unparent_fixed (EggEditableToolbar *etoolbar)
1084 GtkWidget *toolbar, *dock;
1085 g_return_if_fail (GTK_IS_TOOLBAR (etoolbar->priv->fixed_toolbar));
1087 toolbar = etoolbar->priv->fixed_toolbar;
1088 dock = get_dock_nth (etoolbar, 0);
1090 if (dock && toolbar->parent != NULL)
1092 gtk_container_remove (GTK_CONTAINER (dock), toolbar);
1097 update_fixed (EggEditableToolbar *etoolbar)
1099 GtkWidget *toolbar, *dock;
1100 if (!etoolbar->priv->fixed_toolbar) return;
1102 toolbar = etoolbar->priv->fixed_toolbar;
1103 dock = get_dock_nth (etoolbar, 0);
1105 if (dock && toolbar && toolbar->parent == NULL)
1107 gtk_box_pack_end (GTK_BOX (dock), toolbar, FALSE, TRUE, 0);
1109 gtk_widget_show (toolbar);
1111 gtk_widget_set_size_request (dock, -1, -1);
1112 gtk_widget_queue_resize_no_redraw (dock);
1117 toolbar_added_cb (EggToolbarsModel *model,
1119 EggEditableToolbar *etoolbar)
1123 dock = create_dock (etoolbar);
1124 if ((egg_toolbars_model_get_flags (model, position) & EGG_TB_MODEL_HIDDEN) == 0)
1125 gtk_widget_show (dock);
1127 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1129 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1131 gtk_box_reorder_child (GTK_BOX (etoolbar), dock, position);
1133 gtk_widget_show_all (dock);
1135 update_fixed (etoolbar);
1137 toolbar_visibility_refresh (etoolbar);
1141 toolbar_removed_cb (EggToolbarsModel *model,
1143 EggEditableToolbar *etoolbar)
1147 if (position == 0 && etoolbar->priv->fixed_toolbar != NULL)
1149 unparent_fixed (etoolbar);
1152 dock = get_dock_nth (etoolbar, position);
1153 gtk_widget_destroy (dock);
1155 update_fixed (etoolbar);
1157 toolbar_visibility_refresh (etoolbar);
1161 item_added_cb (EggToolbarsModel *model,
1164 EggEditableToolbar *etoolbar)
1170 toolbar = get_toolbar_nth (etoolbar, tpos);
1171 item = create_item_from_position (etoolbar, tpos, ipos);
1172 if (item == NULL) return;
1174 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, ipos);
1176 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1177 configure_item_tooltip (item);
1178 configure_item_cursor (item, etoolbar);
1179 configure_item_sensitivity (item, etoolbar);
1181 dock = get_dock_nth (etoolbar, tpos);
1182 gtk_widget_set_size_request (dock, -1, -1);
1183 gtk_widget_queue_resize_no_redraw (dock);
1185 toolbar_visibility_refresh (etoolbar);
1189 item_removed_cb (EggToolbarsModel *model,
1190 int toolbar_position,
1192 EggEditableToolbar *etoolbar)
1194 EggEditableToolbarPrivate *priv = etoolbar->priv;
1199 toolbar = get_toolbar_nth (etoolbar, toolbar_position);
1200 item = GTK_WIDGET (gtk_toolbar_get_nth_item
1201 (GTK_TOOLBAR (toolbar), position));
1202 g_return_if_fail (item != NULL);
1204 if (item == priv->selected)
1209 gtk_container_remove (GTK_CONTAINER (toolbar), item);
1211 toolbar_visibility_refresh (etoolbar);
1215 egg_editable_toolbar_build (EggEditableToolbar *etoolbar)
1217 int i, l, n_items, n_toolbars;
1218 EggToolbarsModel *model = etoolbar->priv->model;
1220 g_return_if_fail (model != NULL);
1221 g_return_if_fail (etoolbar->priv->manager != NULL);
1223 n_toolbars = egg_toolbars_model_n_toolbars (model);
1225 for (i = 0; i < n_toolbars; i++)
1227 GtkWidget *toolbar, *dock;
1229 dock = create_dock (etoolbar);
1230 if ((egg_toolbars_model_get_flags (model, i) & EGG_TB_MODEL_HIDDEN) == 0)
1231 gtk_widget_show (dock);
1232 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1233 toolbar = get_toolbar_nth (etoolbar, i);
1235 n_items = egg_toolbars_model_n_items (model, i);
1236 for (l = 0; l < n_items; l++)
1240 item = create_item_from_position (etoolbar, i, l);
1243 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, l);
1245 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1246 configure_item_tooltip (item);
1247 configure_item_sensitivity (item, etoolbar);
1251 egg_toolbars_model_remove_item (model, i, l);
1259 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1263 update_fixed (etoolbar);
1266 for (i = 0; i < n_toolbars; i ++)
1268 toolbar_changed_cb (model, i, etoolbar);
1273 egg_editable_toolbar_disconnect_model (EggEditableToolbar *toolbar)
1275 EggToolbarsModel *model = toolbar->priv->model;
1277 g_signal_handlers_disconnect_by_func
1278 (model, G_CALLBACK (item_added_cb), toolbar);
1279 g_signal_handlers_disconnect_by_func
1280 (model, G_CALLBACK (item_removed_cb), toolbar);
1281 g_signal_handlers_disconnect_by_func
1282 (model, G_CALLBACK (toolbar_added_cb), toolbar);
1283 g_signal_handlers_disconnect_by_func
1284 (model, G_CALLBACK (toolbar_removed_cb), toolbar);
1285 g_signal_handlers_disconnect_by_func
1286 (model, G_CALLBACK (toolbar_changed_cb), toolbar);
1290 egg_editable_toolbar_deconstruct (EggEditableToolbar *toolbar)
1292 EggToolbarsModel *model = toolbar->priv->model;
1295 g_return_if_fail (model != NULL);
1297 if (toolbar->priv->fixed_toolbar)
1299 unset_fixed_style (toolbar);
1300 unparent_fixed (toolbar);
1303 children = gtk_container_get_children (GTK_CONTAINER (toolbar));
1304 g_list_foreach (children, (GFunc) gtk_widget_destroy, NULL);
1305 g_list_free (children);
1309 egg_editable_toolbar_set_model (EggEditableToolbar *etoolbar,
1310 EggToolbarsModel *model)
1312 EggEditableToolbarPrivate *priv = etoolbar->priv;
1314 if (priv->model == model) return;
1318 egg_editable_toolbar_disconnect_model (etoolbar);
1319 egg_editable_toolbar_deconstruct (etoolbar);
1321 g_object_unref (priv->model);
1324 priv->model = g_object_ref (model);
1326 egg_editable_toolbar_build (etoolbar);
1328 toolbar_visibility_refresh (etoolbar);
1330 g_signal_connect (model, "item_added",
1331 G_CALLBACK (item_added_cb), etoolbar);
1332 g_signal_connect (model, "item_removed",
1333 G_CALLBACK (item_removed_cb), etoolbar);
1334 g_signal_connect (model, "toolbar_added",
1335 G_CALLBACK (toolbar_added_cb), etoolbar);
1336 g_signal_connect (model, "toolbar_removed",
1337 G_CALLBACK (toolbar_removed_cb), etoolbar);
1338 g_signal_connect (model, "toolbar_changed",
1339 G_CALLBACK (toolbar_changed_cb), etoolbar);
1343 egg_editable_toolbar_init (EggEditableToolbar *etoolbar)
1345 EggEditableToolbarPrivate *priv;
1347 priv = etoolbar->priv = EGG_EDITABLE_TOOLBAR_GET_PRIVATE (etoolbar);
1349 priv->save_hidden = TRUE;
1351 g_signal_connect (etoolbar, "notify::visible",
1352 G_CALLBACK (toolbar_visibility_refresh), NULL);
1356 egg_editable_toolbar_dispose (GObject *object)
1358 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1359 EggEditableToolbarPrivate *priv = etoolbar->priv;
1362 if (priv->fixed_toolbar != NULL)
1364 g_object_unref (priv->fixed_toolbar);
1365 priv->fixed_toolbar = NULL;
1368 if (priv->visibility_paths)
1370 children = priv->visibility_paths;
1371 g_list_foreach (children, (GFunc) g_free, NULL);
1372 g_list_free (children);
1373 priv->visibility_paths = NULL;
1376 g_free (priv->popup_path);
1377 priv->popup_path = NULL;
1379 if (priv->manager != NULL)
1381 if (priv->visibility_id)
1383 gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
1384 priv->visibility_id = 0;
1387 g_object_unref (priv->manager);
1388 priv->manager = NULL;
1393 egg_editable_toolbar_disconnect_model (etoolbar);
1394 g_object_unref (priv->model);
1398 G_OBJECT_CLASS (egg_editable_toolbar_parent_class)->dispose (object);
1402 egg_editable_toolbar_set_ui_manager (EggEditableToolbar *etoolbar,
1403 GtkUIManager *manager)
1405 static const GtkActionEntry actions[] = {
1406 { "MoveToolItem", STOCK_DRAG_MODE, N_("_Move on Toolbar"), NULL,
1407 N_("Move the selected item on the toolbar"), G_CALLBACK (move_item_cb) },
1408 { "RemoveToolItem", GTK_STOCK_REMOVE, N_("_Remove from Toolbar"), NULL,
1409 N_("Remove the selected item from the toolbar"), G_CALLBACK (remove_item_cb) },
1410 { "RemoveToolbar", GTK_STOCK_DELETE, N_("_Delete Toolbar"), NULL,
1411 N_("Remove the selected toolbar"), G_CALLBACK (remove_toolbar_cb) },
1414 etoolbar->priv->manager = g_object_ref (manager);
1416 etoolbar->priv->actions = gtk_action_group_new ("ToolbarActions");
1417 gtk_action_group_set_translation_domain (etoolbar->priv->actions, GETTEXT_PACKAGE);
1418 gtk_action_group_add_actions (etoolbar->priv->actions, actions,
1419 G_N_ELEMENTS (actions), etoolbar);
1420 gtk_ui_manager_insert_action_group (manager, etoolbar->priv->actions, -1);
1421 g_object_unref (etoolbar->priv->actions);
1423 toolbar_visibility_refresh (etoolbar);
1426 GtkWidget * egg_editable_toolbar_get_selected (EggEditableToolbar *etoolbar)
1428 return etoolbar->priv->selected;
1432 egg_editable_toolbar_set_selected (EggEditableToolbar *etoolbar,
1435 GtkWidget *toolbar, *toolitem;
1438 etoolbar->priv->selected = widget;
1440 toolbar = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR) : NULL;
1441 toolitem = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM) : NULL;
1445 gint tpos = get_toolbar_position (etoolbar, toolbar);
1446 editable = ((egg_toolbars_model_get_flags (etoolbar->priv->model, tpos) & EGG_TB_MODEL_NOT_EDITABLE) == 0);
1453 gtk_action_set_visible (find_action (etoolbar, "RemoveToolbar"), (toolbar != NULL) && (etoolbar->priv->edit_mode > 0));
1454 gtk_action_set_visible (find_action (etoolbar, "RemoveToolItem"), (toolitem != NULL) && editable);
1455 gtk_action_set_visible (find_action (etoolbar, "MoveToolItem"), (toolitem != NULL) && editable);
1459 set_edit_mode (EggEditableToolbar *etoolbar,
1462 EggEditableToolbarPrivate *priv = etoolbar->priv;
1465 i = priv->edit_mode;
1472 g_return_if_fail (priv->edit_mode > 0);
1475 i *= priv->edit_mode;
1479 for (i = get_n_toolbars (etoolbar)-1; i >= 0; i--)
1483 toolbar = get_toolbar_nth (etoolbar, i);
1484 n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
1486 if (n_items == 0 && priv->edit_mode == 0)
1488 egg_toolbars_model_remove_toolbar (priv->model, i);
1492 for (l = 0; l < n_items; l++)
1496 item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
1498 configure_item_cursor (item, etoolbar);
1499 configure_item_sensitivity (item, etoolbar);
1507 egg_editable_toolbar_set_property (GObject *object,
1509 const GValue *value,
1512 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1516 case PROP_UI_MANAGER:
1517 egg_editable_toolbar_set_ui_manager (etoolbar, g_value_get_object (value));
1519 case PROP_TOOLBARS_MODEL:
1520 egg_editable_toolbar_set_model (etoolbar, g_value_get_object (value));
1523 egg_editable_toolbar_set_selected (etoolbar, g_value_get_object (value));
1525 case PROP_POPUP_PATH:
1526 etoolbar->priv->popup_path = g_strdup (g_value_get_string (value));
1528 case PROP_EDIT_MODE:
1529 set_edit_mode (etoolbar, g_value_get_boolean (value));
1532 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1538 egg_editable_toolbar_get_property (GObject *object,
1543 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1547 case PROP_UI_MANAGER:
1548 g_value_set_object (value, etoolbar->priv->manager);
1550 case PROP_TOOLBARS_MODEL:
1551 g_value_set_object (value, etoolbar->priv->model);
1554 g_value_set_object (value, etoolbar->priv->selected);
1556 case PROP_EDIT_MODE:
1557 g_value_set_boolean (value, etoolbar->priv->edit_mode>0);
1560 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1566 egg_editable_toolbar_class_init (EggEditableToolbarClass *klass)
1568 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1570 object_class->dispose = egg_editable_toolbar_dispose;
1571 object_class->set_property = egg_editable_toolbar_set_property;
1572 object_class->get_property = egg_editable_toolbar_get_property;
1574 egg_editable_toolbar_signals[ACTION_REQUEST] =
1575 g_signal_new ("action_request",
1576 G_OBJECT_CLASS_TYPE (object_class),
1578 G_STRUCT_OFFSET (EggEditableToolbarClass, action_request),
1579 NULL, NULL, g_cclosure_marshal_VOID__STRING,
1580 G_TYPE_NONE, 1, G_TYPE_STRING);
1582 g_object_class_install_property (object_class,
1584 g_param_spec_object ("ui-manager",
1587 GTK_TYPE_UI_MANAGER,
1588 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1589 g_object_class_install_property (object_class,
1590 PROP_TOOLBARS_MODEL,
1591 g_param_spec_object ("model",
1594 EGG_TYPE_TOOLBARS_MODEL,
1595 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1596 g_object_class_install_property (object_class,
1598 g_param_spec_object ("selected",
1600 "Selected toolitem",
1602 G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1604 g_object_class_install_property (object_class,
1606 g_param_spec_string ("popup-path",
1610 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1612 g_object_class_install_property (object_class,
1614 g_param_spec_boolean ("edit-mode",
1618 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1620 g_type_class_add_private (object_class, sizeof (EggEditableToolbarPrivate));
1624 egg_editable_toolbar_new (GtkUIManager *manager,
1625 const char *popup_path)
1627 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1628 "ui-manager", manager,
1629 "popup-path", popup_path,
1634 egg_editable_toolbar_new_with_model (GtkUIManager *manager,
1635 EggToolbarsModel *model,
1636 const char *popup_path)
1638 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1639 "ui-manager", manager,
1641 "popup-path", popup_path,
1646 egg_editable_toolbar_get_edit_mode (EggEditableToolbar *etoolbar)
1648 EggEditableToolbarPrivate *priv = etoolbar->priv;
1650 return priv->edit_mode > 0;
1654 egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar,
1657 set_edit_mode (etoolbar, mode);
1658 g_object_notify (G_OBJECT (etoolbar), "edit-mode");
1662 egg_editable_toolbar_add_visibility (EggEditableToolbar *etoolbar,
1665 etoolbar->priv->visibility_paths = g_list_prepend
1666 (etoolbar->priv->visibility_paths, g_strdup (path));
1670 egg_editable_toolbar_show (EggEditableToolbar *etoolbar,
1673 EggEditableToolbarPrivate *priv = etoolbar->priv;
1674 EggToolbarsModel *model = priv->model;
1677 n_toolbars = egg_toolbars_model_n_toolbars (model);
1678 for (i = 0; i < n_toolbars; i++)
1680 const char *toolbar_name;
1682 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1683 if (strcmp (toolbar_name, name) == 0)
1685 gtk_widget_show (get_dock_nth (etoolbar, i));
1691 egg_editable_toolbar_hide (EggEditableToolbar *etoolbar,
1694 EggEditableToolbarPrivate *priv = etoolbar->priv;
1695 EggToolbarsModel *model = priv->model;
1698 n_toolbars = egg_toolbars_model_n_toolbars (model);
1699 for (i = 0; i < n_toolbars; i++)
1701 const char *toolbar_name;
1703 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1704 if (strcmp (toolbar_name, name) == 0)
1706 gtk_widget_hide (get_dock_nth (etoolbar, i));
1712 egg_editable_toolbar_set_fixed (EggEditableToolbar *etoolbar,
1713 GtkToolbar *toolbar)
1715 EggEditableToolbarPrivate *priv = etoolbar->priv;
1717 g_return_if_fail (!toolbar || GTK_IS_TOOLBAR (toolbar));
1719 if (priv->fixed_toolbar)
1721 unparent_fixed (etoolbar);
1722 g_object_unref (priv->fixed_toolbar);
1723 priv->fixed_toolbar = NULL;
1728 priv->fixed_toolbar = GTK_WIDGET (toolbar);
1729 gtk_toolbar_set_show_arrow (toolbar, FALSE);
1730 g_object_ref_sink (toolbar);
1733 update_fixed (etoolbar);
1736 #define DEFAULT_ICON_HEIGHT 20
1737 #define DEFAULT_ICON_WIDTH 0
1740 fake_expose_widget (GtkWidget *widget,
1743 GdkWindow *tmp_window;
1744 GdkEventExpose event;
1746 event.type = GDK_EXPOSE;
1747 event.window = pixmap;
1748 event.send_event = FALSE;
1749 event.area = widget->allocation;
1750 event.region = NULL;
1753 tmp_window = widget->window;
1754 widget->window = pixmap;
1755 gtk_widget_send_expose (widget, (GdkEvent *) &event);
1756 widget->window = tmp_window;
1759 /* We should probably experiment some more with this.
1760 * Right now the rendered icon is pretty good for most
1761 * themes. However, the icon is slightly large for themes
1762 * with large toolbar icons.
1765 new_pixbuf_from_widget (GtkWidget *widget)
1769 GtkRequisition requisition;
1770 GtkAllocation allocation;
1777 icon_width = DEFAULT_ICON_WIDTH;
1779 screen = gtk_widget_get_screen (widget);
1781 if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen),
1782 GTK_ICON_SIZE_LARGE_TOOLBAR,
1786 icon_height = DEFAULT_ICON_HEIGHT;
1789 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1791 gtk_container_add (GTK_CONTAINER (window), widget);
1792 gtk_widget_realize (window);
1793 gtk_widget_show (widget);
1794 gtk_widget_realize (widget);
1795 gtk_widget_map (widget);
1797 /* Gtk will never set the width or height of a window to 0. So setting the width to
1798 * 0 and than getting it will provide us with the minimum width needed to render
1799 * the icon correctly, without any additional window background noise.
1800 * This is needed mostly for pixmap based themes.
1802 gtk_window_set_default_size (GTK_WINDOW (window), icon_width, icon_height);
1803 gtk_window_get_size (GTK_WINDOW (window),&icon_width, &icon_height);
1805 gtk_widget_size_request (window, &requisition);
1808 allocation.width = icon_width;
1809 allocation.height = icon_height;
1810 gtk_widget_size_allocate (window, &allocation);
1811 gtk_widget_size_request (window, &requisition);
1813 /* Create a pixmap */
1814 visual = gtk_widget_get_visual (window);
1815 pixmap = gdk_pixmap_new (NULL, icon_width, icon_height, visual->depth);
1816 gdk_drawable_set_colormap (GDK_DRAWABLE (pixmap), gtk_widget_get_colormap (window));
1818 /* Draw the window */
1819 gtk_widget_ensure_style (window);
1820 g_assert (window->style);
1821 g_assert (window->style->font_desc);
1823 fake_expose_widget (window, pixmap);
1824 fake_expose_widget (widget, pixmap);
1826 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, icon_width, icon_height);
1827 gdk_pixbuf_get_from_drawable (pixbuf, pixmap, NULL, 0, 0, 0, 0, icon_width, icon_height);
1829 gtk_widget_destroy (window);
1835 new_separator_pixbuf (void)
1837 GtkWidget *separator;
1840 separator = gtk_vseparator_new ();
1841 pixbuf = new_pixbuf_from_widget (separator);
1846 update_separator_image (GtkImage *image)
1848 GdkPixbuf *pixbuf = new_separator_pixbuf ();
1849 gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
1850 g_object_unref (pixbuf);
1854 style_set_cb (GtkWidget *widget,
1855 GtkStyle *previous_style,
1859 update_separator_image (image);
1864 _egg_editable_toolbar_new_separator_image (void)
1866 GtkWidget *image = gtk_image_new ();
1867 update_separator_image (GTK_IMAGE (image));
1868 g_signal_connect (G_OBJECT (image), "style_set",
1869 G_CALLBACK (style_set_cb), GTK_IMAGE (image));
1875 egg_editable_toolbar_get_model (EggEditableToolbar *etoolbar)
1877 return etoolbar->priv->model;