2 * Copyright (C) 2003, 2004 Marco Pesenti Gritti
3 * Copyright (C) 2003, 2004, 2005 Christian Persch
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "egg-editable-toolbar.h"
25 #include "egg-toolbars-model.h"
26 #include "egg-toolbar-editor.h"
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 showing = GTK_WIDGET_VISIBLE (etoolbar);
877 n_toolbars = egg_toolbars_model_n_toolbars (priv->model);
878 for (i = 0; i < n_toolbars; i++)
880 string = g_string_sized_new (0);
881 n_items = egg_toolbars_model_n_items (priv->model, i);
882 for (k = 0, j = 0; j < n_items; j++)
884 GValue value = { 0, };
888 name = egg_toolbars_model_item_nth (priv->model, i, j);
889 if (name == NULL) continue;
890 action = find_action (etoolbar, name);
891 if (action == NULL) continue;
893 g_value_init (&value, G_TYPE_STRING);
894 g_object_get_property (G_OBJECT (action), "label", &value);
895 name = g_value_get_string (&value);
898 g_value_unset (&value);
901 k += g_utf8_strlen (name, -1) + 2;
904 g_string_append (string, ", ");
907 g_value_unset (&value);
911 g_string_append (string, name);
912 g_value_unset (&value);
916 g_string_append (string, " ...");
919 tmp = g_string_free (string, FALSE);
920 for (j = 0, k = 0; tmp[j]; j++)
922 if (tmp[j] == '_') continue;
927 /* Translaters: This string is for a toggle to display a toolbar.
928 * The name of the toolbar is automatically computed from the widgets
929 * on the toolbar, and is placed at the %s. Note the _ before the %s
930 * which is used to add mnemonics. We know that this is likely to
931 * produce duplicates, but don't worry about it. If your language
932 * normally has a mnemonic at the start, please use the _. If not,
934 action_label = g_strdup_printf (_("Show “_%s”"), tmp);
937 sprintf(action_name, "ToolbarToggle%d", i);
939 if (i >= priv->visibility_actions->len)
941 action = gtk_toggle_action_new (action_name, action_label, NULL, NULL);
942 g_ptr_array_add (priv->visibility_actions, action);
943 g_signal_connect_object (action, "toggled",
944 G_CALLBACK (toggled_visibility_cb),
946 gtk_action_group_add_action (priv->actions, GTK_ACTION (action));
950 action = g_ptr_array_index (priv->visibility_actions, i);
951 g_object_set (action, "label", action_label, NULL);
954 gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i)
955 & EGG_TB_MODEL_NOT_REMOVABLE) == 0);
956 gtk_action_set_sensitive (GTK_ACTION (action), showing);
957 gtk_toggle_action_set_active (action, GTK_WIDGET_VISIBLE
958 (get_dock_nth (etoolbar, i)));
960 for (list = priv->visibility_paths; list != NULL; list = g_list_next (list))
962 gtk_ui_manager_add_ui (priv->manager, priv->visibility_id,
963 (const char *)list->data, action_name, action_name,
964 GTK_UI_MANAGER_MENUITEM, FALSE);
967 g_free (action_label);
970 gtk_ui_manager_ensure_update (priv->manager);
972 while (i < priv->visibility_actions->len)
974 action = g_ptr_array_index (priv->visibility_actions, i);
975 g_ptr_array_remove_index_fast (priv->visibility_actions, i);
976 gtk_action_group_remove_action (priv->actions, GTK_ACTION (action));
982 create_dock (EggEditableToolbar *etoolbar)
984 GtkWidget *toolbar, *hbox;
986 hbox = gtk_hbox_new (0, FALSE);
988 toolbar = gtk_toolbar_new ();
989 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
990 gtk_widget_show (toolbar);
991 gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0);
993 g_signal_connect (toolbar, "drag_drop",
994 G_CALLBACK (toolbar_drag_drop_cb), etoolbar);
995 g_signal_connect (toolbar, "drag_motion",
996 G_CALLBACK (toolbar_drag_motion_cb), etoolbar);
997 g_signal_connect (toolbar, "drag_leave",
998 G_CALLBACK (toolbar_drag_leave_cb), etoolbar);
1000 g_signal_connect (toolbar, "drag_data_received",
1001 G_CALLBACK (toolbar_drag_data_received_cb), etoolbar);
1002 g_signal_connect (toolbar, "popup_context_menu",
1003 G_CALLBACK (popup_context_menu_cb), etoolbar);
1005 configure_drag_dest (etoolbar, GTK_TOOLBAR (toolbar));
1011 set_fixed_style (EggEditableToolbar *t, GtkToolbarStyle style)
1013 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
1014 gtk_toolbar_set_style (GTK_TOOLBAR (t->priv->fixed_toolbar),
1015 style == GTK_TOOLBAR_ICONS ? GTK_TOOLBAR_BOTH_HORIZ : style);
1019 unset_fixed_style (EggEditableToolbar *t)
1021 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
1022 gtk_toolbar_unset_style (GTK_TOOLBAR (t->priv->fixed_toolbar));
1026 toolbar_changed_cb (EggToolbarsModel *model,
1028 EggEditableToolbar *etoolbar)
1031 EggTbModelFlags flags;
1032 GtkToolbarStyle style;
1034 flags = egg_toolbars_model_get_flags (model, position);
1035 toolbar = get_toolbar_nth (etoolbar, position);
1037 if (flags & EGG_TB_MODEL_ICONS)
1039 style = GTK_TOOLBAR_ICONS;
1041 else if (flags & EGG_TB_MODEL_TEXT)
1043 style = GTK_TOOLBAR_TEXT;
1045 else if (flags & EGG_TB_MODEL_BOTH)
1047 style = GTK_TOOLBAR_BOTH;
1049 else if (flags & EGG_TB_MODEL_BOTH_HORIZ)
1051 style = GTK_TOOLBAR_BOTH_HORIZ;
1055 gtk_toolbar_unset_style (GTK_TOOLBAR (toolbar));
1056 if (position == 0 && etoolbar->priv->fixed_toolbar)
1058 unset_fixed_style (etoolbar);
1063 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style);
1064 if (position == 0 && etoolbar->priv->fixed_toolbar)
1066 set_fixed_style (etoolbar, style);
1069 toolbar_visibility_refresh (etoolbar);
1073 unparent_fixed (EggEditableToolbar *etoolbar)
1075 GtkWidget *toolbar, *dock;
1076 g_return_if_fail (GTK_IS_TOOLBAR (etoolbar->priv->fixed_toolbar));
1078 toolbar = etoolbar->priv->fixed_toolbar;
1079 dock = get_dock_nth (etoolbar, 0);
1081 if (dock && toolbar->parent != NULL)
1083 gtk_container_remove (GTK_CONTAINER (dock), toolbar);
1088 update_fixed (EggEditableToolbar *etoolbar)
1090 GtkWidget *toolbar, *dock;
1091 if (!etoolbar->priv->fixed_toolbar) return;
1093 toolbar = etoolbar->priv->fixed_toolbar;
1094 dock = get_dock_nth (etoolbar, 0);
1096 if (dock && toolbar && toolbar->parent == NULL)
1098 gtk_box_pack_end (GTK_BOX (dock), toolbar, FALSE, TRUE, 0);
1100 gtk_widget_show (toolbar);
1102 gtk_widget_set_size_request (dock, -1, -1);
1103 gtk_widget_queue_resize_no_redraw (dock);
1108 toolbar_added_cb (EggToolbarsModel *model,
1110 EggEditableToolbar *etoolbar)
1114 dock = create_dock (etoolbar);
1115 if ((egg_toolbars_model_get_flags (model, position) & EGG_TB_MODEL_HIDDEN) == 0)
1116 gtk_widget_show (dock);
1118 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1120 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1122 gtk_box_reorder_child (GTK_BOX (etoolbar), dock, position);
1124 gtk_widget_show_all (dock);
1126 update_fixed (etoolbar);
1128 toolbar_visibility_refresh (etoolbar);
1132 toolbar_removed_cb (EggToolbarsModel *model,
1134 EggEditableToolbar *etoolbar)
1138 if (position == 0 && etoolbar->priv->fixed_toolbar != NULL)
1140 unparent_fixed (etoolbar);
1143 dock = get_dock_nth (etoolbar, position);
1144 gtk_widget_destroy (dock);
1146 update_fixed (etoolbar);
1148 toolbar_visibility_refresh (etoolbar);
1152 item_added_cb (EggToolbarsModel *model,
1155 EggEditableToolbar *etoolbar)
1161 toolbar = get_toolbar_nth (etoolbar, tpos);
1162 item = create_item_from_position (etoolbar, tpos, ipos);
1163 if (item == NULL) return;
1165 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, ipos);
1167 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1168 configure_item_tooltip (item);
1169 configure_item_cursor (item, etoolbar);
1170 configure_item_sensitivity (item, etoolbar);
1172 dock = get_dock_nth (etoolbar, tpos);
1173 gtk_widget_set_size_request (dock, -1, -1);
1174 gtk_widget_queue_resize_no_redraw (dock);
1176 toolbar_visibility_refresh (etoolbar);
1180 item_removed_cb (EggToolbarsModel *model,
1181 int toolbar_position,
1183 EggEditableToolbar *etoolbar)
1185 EggEditableToolbarPrivate *priv = etoolbar->priv;
1190 toolbar = get_toolbar_nth (etoolbar, toolbar_position);
1191 item = GTK_WIDGET (gtk_toolbar_get_nth_item
1192 (GTK_TOOLBAR (toolbar), position));
1193 g_return_if_fail (item != NULL);
1195 if (item == priv->selected)
1200 gtk_container_remove (GTK_CONTAINER (toolbar), item);
1202 toolbar_visibility_refresh (etoolbar);
1206 egg_editable_toolbar_build (EggEditableToolbar *etoolbar)
1208 int i, l, n_items, n_toolbars;
1209 EggToolbarsModel *model = etoolbar->priv->model;
1211 g_return_if_fail (model != NULL);
1212 g_return_if_fail (etoolbar->priv->manager != NULL);
1214 n_toolbars = egg_toolbars_model_n_toolbars (model);
1216 for (i = 0; i < n_toolbars; i++)
1218 GtkWidget *toolbar, *dock;
1220 dock = create_dock (etoolbar);
1221 if ((egg_toolbars_model_get_flags (model, i) & EGG_TB_MODEL_HIDDEN) == 0)
1222 gtk_widget_show (dock);
1223 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1224 toolbar = get_toolbar_nth (etoolbar, i);
1226 n_items = egg_toolbars_model_n_items (model, i);
1227 for (l = 0; l < n_items; l++)
1231 item = create_item_from_position (etoolbar, i, l);
1234 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, l);
1236 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1237 configure_item_tooltip (item);
1238 configure_item_sensitivity (item, etoolbar);
1242 egg_toolbars_model_remove_item (model, i, l);
1250 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1254 update_fixed (etoolbar);
1257 for (i = 0; i < n_toolbars; i ++)
1259 toolbar_changed_cb (model, i, etoolbar);
1264 egg_editable_toolbar_disconnect_model (EggEditableToolbar *toolbar)
1266 EggToolbarsModel *model = toolbar->priv->model;
1268 g_signal_handlers_disconnect_by_func
1269 (model, G_CALLBACK (item_added_cb), toolbar);
1270 g_signal_handlers_disconnect_by_func
1271 (model, G_CALLBACK (item_removed_cb), toolbar);
1272 g_signal_handlers_disconnect_by_func
1273 (model, G_CALLBACK (toolbar_added_cb), toolbar);
1274 g_signal_handlers_disconnect_by_func
1275 (model, G_CALLBACK (toolbar_removed_cb), toolbar);
1276 g_signal_handlers_disconnect_by_func
1277 (model, G_CALLBACK (toolbar_changed_cb), toolbar);
1281 egg_editable_toolbar_deconstruct (EggEditableToolbar *toolbar)
1283 EggToolbarsModel *model = toolbar->priv->model;
1286 g_return_if_fail (model != NULL);
1288 if (toolbar->priv->fixed_toolbar)
1290 unset_fixed_style (toolbar);
1291 unparent_fixed (toolbar);
1294 children = gtk_container_get_children (GTK_CONTAINER (toolbar));
1295 g_list_foreach (children, (GFunc) gtk_widget_destroy, NULL);
1296 g_list_free (children);
1300 egg_editable_toolbar_set_model (EggEditableToolbar *etoolbar,
1301 EggToolbarsModel *model)
1303 EggEditableToolbarPrivate *priv = etoolbar->priv;
1305 if (priv->model == model) return;
1309 egg_editable_toolbar_disconnect_model (etoolbar);
1310 egg_editable_toolbar_deconstruct (etoolbar);
1312 g_object_unref (priv->model);
1315 priv->model = g_object_ref (model);
1317 egg_editable_toolbar_build (etoolbar);
1319 toolbar_visibility_refresh (etoolbar);
1321 g_signal_connect (model, "item_added",
1322 G_CALLBACK (item_added_cb), etoolbar);
1323 g_signal_connect (model, "item_removed",
1324 G_CALLBACK (item_removed_cb), etoolbar);
1325 g_signal_connect (model, "toolbar_added",
1326 G_CALLBACK (toolbar_added_cb), etoolbar);
1327 g_signal_connect (model, "toolbar_removed",
1328 G_CALLBACK (toolbar_removed_cb), etoolbar);
1329 g_signal_connect (model, "toolbar_changed",
1330 G_CALLBACK (toolbar_changed_cb), etoolbar);
1334 egg_editable_toolbar_init (EggEditableToolbar *etoolbar)
1336 EggEditableToolbarPrivate *priv;
1338 priv = etoolbar->priv = EGG_EDITABLE_TOOLBAR_GET_PRIVATE (etoolbar);
1340 priv->save_hidden = TRUE;
1342 g_signal_connect (etoolbar, "notify::visible",
1343 G_CALLBACK (toolbar_visibility_refresh), NULL);
1347 egg_editable_toolbar_dispose (GObject *object)
1349 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1350 EggEditableToolbarPrivate *priv = etoolbar->priv;
1353 if (priv->fixed_toolbar != NULL)
1355 g_object_unref (priv->fixed_toolbar);
1356 priv->fixed_toolbar = NULL;
1359 if (priv->visibility_paths)
1361 children = priv->visibility_paths;
1362 g_list_foreach (children, (GFunc) g_free, NULL);
1363 g_list_free (children);
1364 priv->visibility_paths = NULL;
1367 g_free (priv->popup_path);
1368 priv->popup_path = NULL;
1370 if (priv->manager != NULL)
1372 if (priv->visibility_id)
1374 gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
1375 priv->visibility_id = 0;
1378 g_object_unref (priv->manager);
1379 priv->manager = NULL;
1384 egg_editable_toolbar_disconnect_model (etoolbar);
1385 g_object_unref (priv->model);
1389 G_OBJECT_CLASS (egg_editable_toolbar_parent_class)->dispose (object);
1393 egg_editable_toolbar_set_ui_manager (EggEditableToolbar *etoolbar,
1394 GtkUIManager *manager)
1396 static const GtkActionEntry actions[] = {
1397 { "MoveToolItem", STOCK_DRAG_MODE, N_("_Move on Toolbar"), NULL,
1398 N_("Move the selected item on the toolbar"), G_CALLBACK (move_item_cb) },
1399 { "RemoveToolItem", GTK_STOCK_REMOVE, N_("_Remove from Toolbar"), NULL,
1400 N_("Remove the selected item from the toolbar"), G_CALLBACK (remove_item_cb) },
1401 { "RemoveToolbar", GTK_STOCK_DELETE, N_("_Delete Toolbar"), NULL,
1402 N_("Remove the selected toolbar"), G_CALLBACK (remove_toolbar_cb) },
1405 etoolbar->priv->manager = g_object_ref (manager);
1407 etoolbar->priv->actions = gtk_action_group_new ("ToolbarActions");
1408 gtk_action_group_set_translation_domain (etoolbar->priv->actions, GETTEXT_PACKAGE);
1409 gtk_action_group_add_actions (etoolbar->priv->actions, actions,
1410 G_N_ELEMENTS (actions), etoolbar);
1411 gtk_ui_manager_insert_action_group (manager, etoolbar->priv->actions, -1);
1412 g_object_unref (etoolbar->priv->actions);
1414 toolbar_visibility_refresh (etoolbar);
1417 GtkWidget * egg_editable_toolbar_get_selected (EggEditableToolbar *etoolbar)
1419 return etoolbar->priv->selected;
1423 egg_editable_toolbar_set_selected (EggEditableToolbar *etoolbar,
1426 GtkWidget *toolbar, *toolitem;
1429 etoolbar->priv->selected = widget;
1431 toolbar = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR) : NULL;
1432 toolitem = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM) : NULL;
1436 gint tpos = get_toolbar_position (etoolbar, toolbar);
1437 editable = ((egg_toolbars_model_get_flags (etoolbar->priv->model, tpos) & EGG_TB_MODEL_NOT_EDITABLE) == 0);
1444 gtk_action_set_visible (find_action (etoolbar, "RemoveToolbar"), (toolbar != NULL) && (etoolbar->priv->edit_mode > 0));
1445 gtk_action_set_visible (find_action (etoolbar, "RemoveToolItem"), (toolitem != NULL) && editable);
1446 gtk_action_set_visible (find_action (etoolbar, "MoveToolItem"), (toolitem != NULL) && editable);
1450 set_edit_mode (EggEditableToolbar *etoolbar,
1453 EggEditableToolbarPrivate *priv = etoolbar->priv;
1456 i = priv->edit_mode;
1463 g_return_if_fail (priv->edit_mode > 0);
1466 i *= priv->edit_mode;
1470 for (i = get_n_toolbars (etoolbar)-1; i >= 0; i--)
1474 toolbar = get_toolbar_nth (etoolbar, i);
1475 n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
1477 if (n_items == 0 && priv->edit_mode == 0)
1479 egg_toolbars_model_remove_toolbar (priv->model, i);
1483 for (l = 0; l < n_items; l++)
1487 item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
1489 configure_item_cursor (item, etoolbar);
1490 configure_item_sensitivity (item, etoolbar);
1498 egg_editable_toolbar_set_property (GObject *object,
1500 const GValue *value,
1503 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1507 case PROP_UI_MANAGER:
1508 egg_editable_toolbar_set_ui_manager (etoolbar, g_value_get_object (value));
1510 case PROP_TOOLBARS_MODEL:
1511 egg_editable_toolbar_set_model (etoolbar, g_value_get_object (value));
1514 egg_editable_toolbar_set_selected (etoolbar, g_value_get_object (value));
1516 case PROP_POPUP_PATH:
1517 etoolbar->priv->popup_path = g_strdup (g_value_get_string (value));
1519 case PROP_EDIT_MODE:
1520 set_edit_mode (etoolbar, g_value_get_boolean (value));
1523 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1529 egg_editable_toolbar_get_property (GObject *object,
1534 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1538 case PROP_UI_MANAGER:
1539 g_value_set_object (value, etoolbar->priv->manager);
1541 case PROP_TOOLBARS_MODEL:
1542 g_value_set_object (value, etoolbar->priv->model);
1545 g_value_set_object (value, etoolbar->priv->selected);
1547 case PROP_EDIT_MODE:
1548 g_value_set_boolean (value, etoolbar->priv->edit_mode>0);
1551 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1557 egg_editable_toolbar_class_init (EggEditableToolbarClass *klass)
1559 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1561 object_class->dispose = egg_editable_toolbar_dispose;
1562 object_class->set_property = egg_editable_toolbar_set_property;
1563 object_class->get_property = egg_editable_toolbar_get_property;
1565 egg_editable_toolbar_signals[ACTION_REQUEST] =
1566 g_signal_new ("action_request",
1567 G_OBJECT_CLASS_TYPE (object_class),
1569 G_STRUCT_OFFSET (EggEditableToolbarClass, action_request),
1570 NULL, NULL, g_cclosure_marshal_VOID__STRING,
1571 G_TYPE_NONE, 1, G_TYPE_STRING);
1573 g_object_class_install_property (object_class,
1575 g_param_spec_object ("ui-manager",
1578 GTK_TYPE_UI_MANAGER,
1579 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1580 g_object_class_install_property (object_class,
1581 PROP_TOOLBARS_MODEL,
1582 g_param_spec_object ("model",
1585 EGG_TYPE_TOOLBARS_MODEL,
1586 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1587 g_object_class_install_property (object_class,
1589 g_param_spec_object ("selected",
1591 "Selected toolitem",
1593 G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1595 g_object_class_install_property (object_class,
1597 g_param_spec_string ("popup-path",
1601 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1603 g_object_class_install_property (object_class,
1605 g_param_spec_boolean ("edit-mode",
1609 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1611 g_type_class_add_private (object_class, sizeof (EggEditableToolbarPrivate));
1615 egg_editable_toolbar_new (GtkUIManager *manager,
1616 const char *popup_path)
1618 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1619 "ui-manager", manager,
1620 "popup-path", popup_path,
1625 egg_editable_toolbar_new_with_model (GtkUIManager *manager,
1626 EggToolbarsModel *model,
1627 const char *popup_path)
1629 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1630 "ui-manager", manager,
1632 "popup-path", popup_path,
1637 egg_editable_toolbar_get_edit_mode (EggEditableToolbar *etoolbar)
1639 EggEditableToolbarPrivate *priv = etoolbar->priv;
1641 return priv->edit_mode > 0;
1645 egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar,
1648 set_edit_mode (etoolbar, mode);
1649 g_object_notify (G_OBJECT (etoolbar), "edit-mode");
1653 egg_editable_toolbar_add_visibility (EggEditableToolbar *etoolbar,
1656 etoolbar->priv->visibility_paths = g_list_prepend
1657 (etoolbar->priv->visibility_paths, g_strdup (path));
1661 egg_editable_toolbar_show (EggEditableToolbar *etoolbar,
1664 EggEditableToolbarPrivate *priv = etoolbar->priv;
1665 EggToolbarsModel *model = priv->model;
1668 n_toolbars = egg_toolbars_model_n_toolbars (model);
1669 for (i = 0; i < n_toolbars; i++)
1671 const char *toolbar_name;
1673 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1674 if (strcmp (toolbar_name, name) == 0)
1676 gtk_widget_show (get_dock_nth (etoolbar, i));
1682 egg_editable_toolbar_hide (EggEditableToolbar *etoolbar,
1685 EggEditableToolbarPrivate *priv = etoolbar->priv;
1686 EggToolbarsModel *model = priv->model;
1689 n_toolbars = egg_toolbars_model_n_toolbars (model);
1690 for (i = 0; i < n_toolbars; i++)
1692 const char *toolbar_name;
1694 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1695 if (strcmp (toolbar_name, name) == 0)
1697 gtk_widget_hide (get_dock_nth (etoolbar, i));
1703 egg_editable_toolbar_set_fixed (EggEditableToolbar *etoolbar,
1704 GtkToolbar *toolbar)
1706 EggEditableToolbarPrivate *priv = etoolbar->priv;
1708 g_return_if_fail (!toolbar || GTK_IS_TOOLBAR (toolbar));
1710 if (priv->fixed_toolbar)
1712 unparent_fixed (etoolbar);
1713 g_object_unref (priv->fixed_toolbar);
1714 priv->fixed_toolbar = NULL;
1719 priv->fixed_toolbar = GTK_WIDGET (toolbar);
1720 gtk_toolbar_set_show_arrow (toolbar, FALSE);
1721 g_object_ref_sink (toolbar);
1724 update_fixed (etoolbar);
1727 #define DEFAULT_ICON_HEIGHT 20
1728 #define DEFAULT_ICON_WIDTH 0
1731 fake_expose_widget (GtkWidget *widget,
1734 GdkWindow *tmp_window;
1735 GdkEventExpose event;
1737 event.type = GDK_EXPOSE;
1738 event.window = pixmap;
1739 event.send_event = FALSE;
1740 event.area = widget->allocation;
1741 event.region = NULL;
1744 tmp_window = widget->window;
1745 widget->window = pixmap;
1746 gtk_widget_send_expose (widget, (GdkEvent *) &event);
1747 widget->window = tmp_window;
1750 /* We should probably experiment some more with this.
1751 * Right now the rendered icon is pretty good for most
1752 * themes. However, the icon is slightly large for themes
1753 * with large toolbar icons.
1756 new_pixbuf_from_widget (GtkWidget *widget)
1760 GtkRequisition requisition;
1761 GtkAllocation allocation;
1768 icon_width = DEFAULT_ICON_WIDTH;
1770 screen = gtk_widget_get_screen (widget);
1772 if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen),
1773 GTK_ICON_SIZE_LARGE_TOOLBAR,
1777 icon_height = DEFAULT_ICON_HEIGHT;
1780 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1782 gtk_container_add (GTK_CONTAINER (window), widget);
1783 gtk_widget_realize (window);
1784 gtk_widget_show (widget);
1785 gtk_widget_realize (widget);
1786 gtk_widget_map (widget);
1788 /* Gtk will never set the width or height of a window to 0. So setting the width to
1789 * 0 and than getting it will provide us with the minimum width needed to render
1790 * the icon correctly, without any additional window background noise.
1791 * This is needed mostly for pixmap based themes.
1793 gtk_window_set_default_size (GTK_WINDOW (window), icon_width, icon_height);
1794 gtk_window_get_size (GTK_WINDOW (window),&icon_width, &icon_height);
1796 gtk_widget_size_request (window, &requisition);
1799 allocation.width = icon_width;
1800 allocation.height = icon_height;
1801 gtk_widget_size_allocate (window, &allocation);
1802 gtk_widget_size_request (window, &requisition);
1804 /* Create a pixmap */
1805 visual = gtk_widget_get_visual (window);
1806 pixmap = gdk_pixmap_new (NULL, icon_width, icon_height, visual->depth);
1807 gdk_drawable_set_colormap (GDK_DRAWABLE (pixmap), gtk_widget_get_colormap (window));
1809 /* Draw the window */
1810 gtk_widget_ensure_style (window);
1811 g_assert (window->style);
1812 g_assert (window->style->font_desc);
1814 fake_expose_widget (window, pixmap);
1815 fake_expose_widget (widget, pixmap);
1817 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, icon_width, icon_height);
1818 gdk_pixbuf_get_from_drawable (pixbuf, pixmap, NULL, 0, 0, 0, 0, icon_width, icon_height);
1820 gtk_widget_destroy (window);
1826 new_separator_pixbuf (void)
1828 GtkWidget *separator;
1831 separator = gtk_vseparator_new ();
1832 pixbuf = new_pixbuf_from_widget (separator);
1837 update_separator_image (GtkImage *image)
1839 GdkPixbuf *pixbuf = new_separator_pixbuf ();
1840 gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
1841 g_object_unref (pixbuf);
1845 style_set_cb (GtkWidget *widget,
1846 GtkStyle *previous_style,
1850 update_separator_image (image);
1855 _egg_editable_toolbar_new_separator_image (void)
1857 GtkWidget *image = gtk_image_new ();
1858 update_separator_image (GTK_IMAGE (image));
1859 g_signal_connect (G_OBJECT (image), "style_set",
1860 G_CALLBACK (style_set_cb), GTK_IMAGE (image));
1866 egg_editable_toolbar_get_model (EggEditableToolbar *etoolbar)
1868 return etoolbar->priv->model;