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 action = g_object_get_data (G_OBJECT (widget), "gtk-action");
204 if (action == NULL) return;
206 flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model,
207 gtk_action_get_name (action));
208 if (!(flags & EGG_TB_MODEL_NAME_INFINITE))
210 flags &= ~EGG_TB_MODEL_NAME_USED;
211 egg_toolbars_model_set_name_flags (etoolbar->priv->model,
212 gtk_action_get_name (action),
218 drag_end_cb (GtkWidget *widget,
219 GdkDragContext *context,
220 EggEditableToolbar *etoolbar)
225 if (gtk_widget_get_parent (widget) != NULL)
227 gtk_widget_show (widget);
229 action = g_object_get_data (G_OBJECT (widget), "gtk-action");
230 if (action == NULL) return;
232 flags = egg_toolbars_model_get_name_flags (etoolbar->priv->model,
233 gtk_action_get_name (action));
234 if (!(flags & EGG_TB_MODEL_NAME_INFINITE))
236 flags |= EGG_TB_MODEL_NAME_USED;
237 egg_toolbars_model_set_name_flags (etoolbar->priv->model,
238 gtk_action_get_name (action),
245 drag_data_get_cb (GtkWidget *widget,
246 GdkDragContext *context,
247 GtkSelectionData *selection_data,
250 EggEditableToolbar *etoolbar)
252 EggToolbarsModel *model;
256 g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (etoolbar));
257 model = egg_editable_toolbar_get_model (etoolbar);
259 name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
262 name = g_object_get_data (G_OBJECT (gtk_widget_get_parent (widget)), EGG_ITEM_NAME);
263 g_return_if_fail (name != NULL);
266 data = egg_toolbars_model_get_data (model, selection_data->target, name);
269 gtk_selection_data_set (selection_data, selection_data->target, 8, (unsigned char *)data, strlen (data));
275 move_item_cb (GtkAction *action,
276 EggEditableToolbar *etoolbar)
278 GtkWidget *toolitem = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM);
279 GtkTargetList *list = gtk_target_list_new (dest_drag_types, G_N_ELEMENTS (dest_drag_types));
281 GdkEvent *realevent = gtk_get_current_event();
282 GdkEventMotion event;
283 event.type = GDK_MOTION_NOTIFY;
284 event.window = realevent->any.window;
285 event.send_event = FALSE;
287 event.time = gdk_event_get_time (realevent);
288 gdk_event_get_state (realevent, &event.state);
289 gdk_event_get_coords (realevent, &event.x, &event.y);
290 gdk_event_get_root_coords (realevent, &event.x_root, &event.y_root);
292 gtk_drag_begin (toolitem, list, GDK_ACTION_MOVE, 1, (GdkEvent *)&event);
293 gtk_target_list_unref (list);
297 remove_item_cb (GtkAction *action,
298 EggEditableToolbar *etoolbar)
300 GtkWidget *toolitem = gtk_widget_get_ancestor (egg_editable_toolbar_get_selected (etoolbar), GTK_TYPE_TOOL_ITEM);
301 int pos, toolbar_pos;
303 toolbar_pos = get_toolbar_position (etoolbar, toolitem->parent);
304 pos = gtk_toolbar_get_item_index (GTK_TOOLBAR (toolitem->parent),
305 GTK_TOOL_ITEM (toolitem));
307 egg_toolbars_model_remove_item (etoolbar->priv->model,
310 if (egg_toolbars_model_n_items (etoolbar->priv->model, toolbar_pos) == 0)
312 egg_toolbars_model_remove_toolbar (etoolbar->priv->model, toolbar_pos);
317 remove_toolbar_cb (GtkAction *action,
318 EggEditableToolbar *etoolbar)
320 GtkWidget *selected = egg_editable_toolbar_get_selected (etoolbar);
321 GtkWidget *toolbar = gtk_widget_get_ancestor (selected, GTK_TYPE_TOOLBAR);
324 toolbar_pos = get_toolbar_position (etoolbar, toolbar);
325 egg_toolbars_model_remove_toolbar (etoolbar->priv->model, toolbar_pos);
329 popup_context_deactivate (GtkMenuShell *menu,
330 EggEditableToolbar *etoolbar)
332 egg_editable_toolbar_set_selected (etoolbar, NULL);
333 g_object_notify (G_OBJECT (etoolbar), "selected");
337 popup_context_menu_cb (GtkWidget *toolbar,
341 EggEditableToolbar *etoolbar)
343 if (etoolbar->priv->popup_path != NULL)
347 egg_editable_toolbar_set_selected (etoolbar, toolbar);
348 g_object_notify (G_OBJECT (etoolbar), "selected");
350 menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
351 etoolbar->priv->popup_path));
352 g_return_if_fail (menu != NULL);
353 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, button_number, gtk_get_current_event_time ());
354 g_signal_connect_object (menu, "selection-done",
355 G_CALLBACK (popup_context_deactivate),
361 button_press_event_cb (GtkWidget *widget,
362 GdkEventButton *event,
363 EggEditableToolbar *etoolbar)
365 if (event->button == 3 && etoolbar->priv->popup_path != NULL)
369 egg_editable_toolbar_set_selected (etoolbar, widget);
370 g_object_notify (G_OBJECT (etoolbar), "selected");
372 menu = GTK_MENU (gtk_ui_manager_get_widget (etoolbar->priv->manager,
373 etoolbar->priv->popup_path));
374 g_return_val_if_fail (menu != NULL, FALSE);
375 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button, event->time);
376 g_signal_connect_object (menu, "selection-done",
377 G_CALLBACK (popup_context_deactivate),
387 configure_item_sensitivity (GtkToolItem *item, EggEditableToolbar *etoolbar)
392 name = g_object_get_data (G_OBJECT (item), EGG_ITEM_NAME);
393 action = name ? find_action (etoolbar, name) : NULL;
397 g_object_notify (G_OBJECT (action), "sensitive");
400 gtk_tool_item_set_use_drag_window (item,
401 (etoolbar->priv->edit_mode > 0) ||
402 GTK_IS_SEPARATOR_TOOL_ITEM (item));
407 configure_item_cursor (GtkToolItem *item,
408 EggEditableToolbar *etoolbar)
410 EggEditableToolbarPrivate *priv = etoolbar->priv;
411 GtkWidget *widget = GTK_WIDGET (item);
413 if (widget->window != NULL)
415 if (priv->edit_mode > 0)
419 GdkPixbuf *pixbuf = NULL;
421 screen = gtk_widget_get_screen (GTK_WIDGET (etoolbar));
423 cursor = gdk_cursor_new_for_display (gdk_screen_get_display (screen),
425 gdk_window_set_cursor (widget->window, cursor);
426 gdk_cursor_unref (cursor);
428 gtk_drag_source_set (widget, GDK_BUTTON1_MASK, dest_drag_types,
429 G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE);
430 if (GTK_IS_SEPARATOR_TOOL_ITEM (item))
432 pixbuf = new_separator_pixbuf ();
436 char *icon_name=NULL;
441 name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME);
442 action = name ? find_action (etoolbar, name) : NULL;
446 g_object_get (action,
447 "icon-name", &icon_name,
448 "stock-id", &stock_id,
454 GtkIconTheme *icon_theme;
455 GtkSettings *settings;
458 screen = gtk_widget_get_screen (widget);
459 icon_theme = gtk_icon_theme_get_for_screen (screen);
460 settings = gtk_settings_get_for_screen (screen);
462 if (!gtk_icon_size_lookup_for_settings (settings,
463 GTK_ICON_SIZE_LARGE_TOOLBAR,
469 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name,
470 MIN (width, height), 0, NULL);
474 pixbuf = gtk_widget_render_icon (widget, stock_id,
475 GTK_ICON_SIZE_LARGE_TOOLBAR, NULL);
481 if (G_UNLIKELY (!pixbuf))
485 gtk_drag_source_set_icon_pixbuf (widget, pixbuf);
486 g_object_unref (pixbuf);
491 gdk_window_set_cursor (GTK_WIDGET(item)->window, NULL);
498 configure_item_tooltip (GtkToolItem *item)
500 GtkAction *action = g_object_get_data (G_OBJECT (item),
505 g_object_notify (G_OBJECT (action), "tooltip");
511 connect_widget_signals (GtkWidget *proxy, EggEditableToolbar *etoolbar)
513 if (GTK_IS_CONTAINER (proxy))
515 gtk_container_forall (GTK_CONTAINER (proxy),
516 (GtkCallback) connect_widget_signals,
517 (gpointer) etoolbar);
520 if (GTK_IS_TOOL_ITEM (proxy))
522 g_signal_connect_object (proxy, "drag_begin",
523 G_CALLBACK (drag_begin_cb),
525 g_signal_connect_object (proxy, "drag_end",
526 G_CALLBACK (drag_end_cb),
528 g_signal_connect_object (proxy, "drag_data_get",
529 G_CALLBACK (drag_data_get_cb),
531 g_signal_connect_object (proxy, "drag_data_delete",
532 G_CALLBACK (drag_data_delete_cb),
536 if (GTK_IS_BUTTON (proxy) || GTK_IS_TOOL_ITEM (proxy))
538 g_signal_connect_object (proxy, "button-press-event",
539 G_CALLBACK (button_press_event_cb),
545 action_sensitive_cb (GtkAction *action,
549 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR
550 (gtk_widget_get_ancestor (GTK_WIDGET (item), EGG_TYPE_EDITABLE_TOOLBAR));
552 if (etoolbar->priv->edit_mode > 0)
554 gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
559 create_item_from_action (EggEditableToolbar *etoolbar,
564 g_return_val_if_fail (name != NULL, NULL);
566 if (strcmp (name, "_separator") == 0)
568 item = gtk_separator_tool_item_new ();
572 GtkAction *action = find_action (etoolbar, name);
573 if (action == NULL) return NULL;
575 item = GTK_TOOL_ITEM (gtk_action_create_tool_item (action));
577 /* Normally done on-demand by the GtkUIManager, but no
578 * such demand may have been made yet, so do it ourselves.
580 gtk_action_set_accel_group
581 (action, gtk_ui_manager_get_accel_group(etoolbar->priv->manager));
583 g_signal_connect_object (action, "notify::sensitive",
584 G_CALLBACK (action_sensitive_cb), item, 0);
587 gtk_widget_show (GTK_WIDGET (item));
589 g_object_set_data_full (G_OBJECT (item), EGG_ITEM_NAME,
590 g_strdup (name), g_free);
596 create_item_from_position (EggEditableToolbar *etoolbar,
597 int toolbar_position,
603 name = egg_toolbars_model_item_nth (etoolbar->priv->model, toolbar_position, position);
604 item = create_item_from_action (etoolbar, name);
610 toolbar_drag_data_received_cb (GtkToolbar *toolbar,
611 GdkDragContext *context,
614 GtkSelectionData *selection_data,
617 EggEditableToolbar *etoolbar)
619 /* This function can be called for two reasons
621 * (1) drag_motion() needs an item to pass to
622 * gtk_toolbar_set_drop_highlight_item(). We can
623 * recognize this case by etoolbar->priv->pending being TRUE
624 * We should just create an item and return.
626 * (2) The drag has finished, and drag_drop() wants us to
627 * actually add a new item to the toolbar.
630 GdkAtom type = selection_data->type;
631 const char *data = (char *)selection_data->data;
635 gboolean used = FALSE;
637 /* Find out where the drop is occuring, and the name of what is being dropped. */
638 if (selection_data->length >= 0)
640 ipos = gtk_toolbar_get_drop_index (toolbar, x, y);
641 name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, FALSE);
644 used = ((egg_toolbars_model_get_name_flags (etoolbar->priv->model, name) & EGG_TB_MODEL_NAME_USED) != 0);
648 /* If we just want a highlight item, then . */
649 if (etoolbar->priv->dnd_pending > 0)
651 etoolbar->priv->dnd_pending--;
653 if (name != NULL && etoolbar->priv->dnd_toolbar == toolbar && !used)
655 etoolbar->priv->dnd_toolitem = create_item_from_action (etoolbar, name);
656 gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar,
657 etoolbar->priv->dnd_toolitem, ipos);
662 gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
663 etoolbar->priv->dnd_toolbar = NULL;
664 etoolbar->priv->dnd_toolitem = NULL;
666 /* If we don't have a name to use yet, try to create one. */
667 if (name == NULL && selection_data->length >= 0)
669 name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, TRUE);
672 if (name != NULL && !used)
674 gint tpos = get_toolbar_position (etoolbar, GTK_WIDGET (toolbar));
675 egg_toolbars_model_add_item (etoolbar->priv->model, tpos, ipos, name);
676 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
680 gtk_drag_finish (context, FALSE, context->action == GDK_ACTION_MOVE, time);
688 toolbar_drag_drop_cb (GtkToolbar *toolbar,
689 GdkDragContext *context,
693 EggEditableToolbar *etoolbar)
697 target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL);
698 if (target != GDK_NONE)
700 gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
708 toolbar_drag_motion_cb (GtkToolbar *toolbar,
709 GdkDragContext *context,
713 EggEditableToolbar *etoolbar)
715 GdkAtom target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL);
716 if (target == GDK_NONE)
718 gdk_drag_status (context, 0, time);
722 /* Make ourselves the current dnd toolbar, and request a highlight item. */
723 if (etoolbar->priv->dnd_toolbar != toolbar)
725 etoolbar->priv->dnd_toolbar = toolbar;
726 etoolbar->priv->dnd_toolitem = NULL;
727 etoolbar->priv->dnd_pending++;
728 gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
731 /* If a highlight item is available, use it. */
732 else if (etoolbar->priv->dnd_toolitem)
734 gint ipos = gtk_toolbar_get_drop_index (etoolbar->priv->dnd_toolbar, x, y);
735 gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar,
736 etoolbar->priv->dnd_toolitem, ipos);
739 gdk_drag_status (context, context->suggested_action, time);
745 toolbar_drag_leave_cb (GtkToolbar *toolbar,
746 GdkDragContext *context,
748 EggEditableToolbar *etoolbar)
750 gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
752 /* If we were the current dnd toolbar target, remove the item. */
753 if (etoolbar->priv->dnd_toolbar == toolbar)
755 etoolbar->priv->dnd_toolbar = NULL;
756 etoolbar->priv->dnd_toolitem = NULL;
761 configure_drag_dest (EggEditableToolbar *etoolbar,
764 EggToolbarsItemType *type;
765 GtkTargetList *targets;
768 /* Make every toolbar able to receive drag-drops. */
769 gtk_drag_dest_set (GTK_WIDGET (toolbar), 0,
770 dest_drag_types, G_N_ELEMENTS (dest_drag_types),
771 GDK_ACTION_MOVE | GDK_ACTION_COPY);
773 /* Add any specialist drag-drop abilities. */
774 targets = gtk_drag_dest_get_target_list (GTK_WIDGET (toolbar));
775 list = egg_toolbars_model_get_types (etoolbar->priv->model);
779 if (type->new_name != NULL || type->get_name != NULL)
780 gtk_target_list_add (targets, type->type, 0, 0);
786 toggled_visibility_cb (GtkToggleAction *action,
787 EggEditableToolbar *etoolbar)
789 EggEditableToolbarPrivate *priv = etoolbar->priv;
791 EggTbModelFlags flags;
795 visible = gtk_toggle_action_get_active (action);
796 for (i = 0; i < priv->visibility_actions->len; i++)
797 if (g_ptr_array_index (priv->visibility_actions, i) == action)
800 g_return_if_fail (i < priv->visibility_actions->len);
802 dock = get_dock_nth (etoolbar, i);
805 gtk_widget_show (dock);
809 gtk_widget_hide (dock);
812 if (priv->save_hidden)
814 flags = egg_toolbars_model_get_flags (priv->model, i);
818 flags &= ~(EGG_TB_MODEL_HIDDEN);
822 flags |= (EGG_TB_MODEL_HIDDEN);
825 egg_toolbars_model_set_flags (priv->model, i, flags);
830 toolbar_visibility_refresh (EggEditableToolbar *etoolbar)
832 EggEditableToolbarPrivate *priv = etoolbar->priv;
833 gint n_toolbars, n_items, i, j, k;
834 GtkToggleAction *action;
838 char action_name[40];
842 if (priv == NULL || priv->model == NULL || priv->manager == NULL ||
843 priv->visibility_paths == NULL || priv->actions == NULL)
848 if (priv->visibility_actions == NULL)
850 priv->visibility_actions = g_ptr_array_new ();
853 if (priv->visibility_id != 0)
855 gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
858 priv->visibility_id = gtk_ui_manager_new_merge_id (priv->manager);
860 showing = GTK_WIDGET_VISIBLE (etoolbar);
862 n_toolbars = egg_toolbars_model_n_toolbars (priv->model);
863 for (i = 0; i < n_toolbars; i++)
865 string = g_string_sized_new (0);
866 n_items = egg_toolbars_model_n_items (priv->model, i);
867 for (k = 0, j = 0; j < n_items; j++)
869 GValue value = { 0, };
873 name = egg_toolbars_model_item_nth (priv->model, i, j);
874 if (name == NULL) continue;
875 action = find_action (etoolbar, name);
876 if (action == NULL) continue;
878 g_value_init (&value, G_TYPE_STRING);
879 g_object_get_property (G_OBJECT (action), "label", &value);
880 name = g_value_get_string (&value);
883 g_value_unset (&value);
886 k += g_utf8_strlen (name, -1) + 2;
889 g_string_append (string, ", ");
892 g_value_unset (&value);
896 g_string_append (string, name);
897 g_value_unset (&value);
901 g_string_append (string, " ...");
904 tmp = g_string_free (string, FALSE);
905 for (j = 0, k = 0; tmp[j]; j++)
907 if (tmp[j] == '_') continue;
912 /* Translaters: This string is for a toggle to display a toolbar.
913 * The name of the toolbar is automatically computed from the widgets
914 * on the toolbar, and is placed at the %s. Note the _ before the %s
915 * which is used to add mnemonics. We know that this is likely to
916 * produce duplicates, but don't worry about it. If your language
917 * normally has a mnemonic at the start, please use the _. If not,
919 action_label = g_strdup_printf (_("Show “_%s”"), tmp);
922 sprintf(action_name, "ToolbarToggle%d", i);
924 if (i >= priv->visibility_actions->len)
926 action = gtk_toggle_action_new (action_name, action_label, NULL, NULL);
927 g_ptr_array_add (priv->visibility_actions, action);
928 g_signal_connect_object (action, "toggled",
929 G_CALLBACK (toggled_visibility_cb),
931 gtk_action_group_add_action (priv->actions, GTK_ACTION (action));
935 action = g_ptr_array_index (priv->visibility_actions, i);
936 g_object_set (action, "label", action_label, NULL);
939 gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i)
940 & EGG_TB_MODEL_NOT_REMOVABLE) == 0);
941 gtk_action_set_sensitive (GTK_ACTION (action), showing);
942 gtk_toggle_action_set_active (action, GTK_WIDGET_VISIBLE
943 (get_dock_nth (etoolbar, i)));
945 for (list = priv->visibility_paths; list != NULL; list = g_list_next (list))
947 gtk_ui_manager_add_ui (priv->manager, priv->visibility_id,
948 (const char *)list->data, action_name, action_name,
949 GTK_UI_MANAGER_MENUITEM, FALSE);
952 g_free (action_label);
955 gtk_ui_manager_ensure_update (priv->manager);
957 while (i < priv->visibility_actions->len)
959 action = g_ptr_array_index (priv->visibility_actions, i);
960 g_ptr_array_remove_index_fast (priv->visibility_actions, i);
961 gtk_action_group_remove_action (priv->actions, GTK_ACTION (action));
967 create_dock (EggEditableToolbar *etoolbar)
969 GtkWidget *toolbar, *hbox;
971 hbox = gtk_hbox_new (0, FALSE);
973 toolbar = gtk_toolbar_new ();
974 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
975 gtk_widget_show (toolbar);
976 gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0);
978 g_signal_connect (toolbar, "drag_drop",
979 G_CALLBACK (toolbar_drag_drop_cb), etoolbar);
980 g_signal_connect (toolbar, "drag_motion",
981 G_CALLBACK (toolbar_drag_motion_cb), etoolbar);
982 g_signal_connect (toolbar, "drag_leave",
983 G_CALLBACK (toolbar_drag_leave_cb), etoolbar);
985 g_signal_connect (toolbar, "drag_data_received",
986 G_CALLBACK (toolbar_drag_data_received_cb), etoolbar);
987 g_signal_connect (toolbar, "popup_context_menu",
988 G_CALLBACK (popup_context_menu_cb), etoolbar);
990 configure_drag_dest (etoolbar, GTK_TOOLBAR (toolbar));
996 set_fixed_style (EggEditableToolbar *t, GtkToolbarStyle style)
998 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
999 gtk_toolbar_set_style (GTK_TOOLBAR (t->priv->fixed_toolbar),
1000 style == GTK_TOOLBAR_ICONS ? GTK_TOOLBAR_BOTH_HORIZ : style);
1004 unset_fixed_style (EggEditableToolbar *t)
1006 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
1007 gtk_toolbar_unset_style (GTK_TOOLBAR (t->priv->fixed_toolbar));
1011 toolbar_changed_cb (EggToolbarsModel *model,
1013 EggEditableToolbar *etoolbar)
1016 EggTbModelFlags flags;
1017 GtkToolbarStyle style;
1019 flags = egg_toolbars_model_get_flags (model, position);
1020 toolbar = get_toolbar_nth (etoolbar, position);
1022 if (flags & EGG_TB_MODEL_ICONS)
1024 style = GTK_TOOLBAR_ICONS;
1026 else if (flags & EGG_TB_MODEL_TEXT)
1028 style = GTK_TOOLBAR_TEXT;
1030 else if (flags & EGG_TB_MODEL_BOTH)
1032 style = GTK_TOOLBAR_BOTH;
1034 else if (flags & EGG_TB_MODEL_BOTH_HORIZ)
1036 style = GTK_TOOLBAR_BOTH_HORIZ;
1040 gtk_toolbar_unset_style (GTK_TOOLBAR (toolbar));
1041 if (position == 0 && etoolbar->priv->fixed_toolbar)
1043 unset_fixed_style (etoolbar);
1048 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style);
1049 if (position == 0 && etoolbar->priv->fixed_toolbar)
1051 set_fixed_style (etoolbar, style);
1054 toolbar_visibility_refresh (etoolbar);
1058 unparent_fixed (EggEditableToolbar *etoolbar)
1060 GtkWidget *toolbar, *dock;
1061 g_return_if_fail (GTK_IS_TOOLBAR (etoolbar->priv->fixed_toolbar));
1063 toolbar = etoolbar->priv->fixed_toolbar;
1064 dock = get_dock_nth (etoolbar, 0);
1066 if (dock && toolbar->parent != NULL)
1068 gtk_container_remove (GTK_CONTAINER (dock), toolbar);
1073 update_fixed (EggEditableToolbar *etoolbar)
1075 GtkWidget *toolbar, *dock;
1076 if (!etoolbar->priv->fixed_toolbar) return;
1078 toolbar = etoolbar->priv->fixed_toolbar;
1079 dock = get_dock_nth (etoolbar, 0);
1081 if (dock && toolbar && toolbar->parent == NULL)
1083 gtk_box_pack_end (GTK_BOX (dock), toolbar, FALSE, TRUE, 0);
1085 gtk_widget_show (toolbar);
1087 gtk_widget_set_size_request (dock, -1, -1);
1088 gtk_widget_queue_resize_no_redraw (dock);
1093 toolbar_added_cb (EggToolbarsModel *model,
1095 EggEditableToolbar *etoolbar)
1099 dock = create_dock (etoolbar);
1100 if ((egg_toolbars_model_get_flags (model, position) & EGG_TB_MODEL_HIDDEN) == 0)
1101 gtk_widget_show (dock);
1103 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1105 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1107 gtk_box_reorder_child (GTK_BOX (etoolbar), dock, position);
1109 gtk_widget_show_all (dock);
1111 update_fixed (etoolbar);
1113 toolbar_visibility_refresh (etoolbar);
1117 toolbar_removed_cb (EggToolbarsModel *model,
1119 EggEditableToolbar *etoolbar)
1123 if (position == 0 && etoolbar->priv->fixed_toolbar != NULL)
1125 unparent_fixed (etoolbar);
1128 dock = get_dock_nth (etoolbar, position);
1129 gtk_widget_destroy (dock);
1131 update_fixed (etoolbar);
1133 toolbar_visibility_refresh (etoolbar);
1137 item_added_cb (EggToolbarsModel *model,
1140 EggEditableToolbar *etoolbar)
1146 toolbar = get_toolbar_nth (etoolbar, tpos);
1147 item = create_item_from_position (etoolbar, tpos, ipos);
1148 if (item == NULL) return;
1150 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, ipos);
1152 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1153 configure_item_tooltip (item);
1154 configure_item_cursor (item, etoolbar);
1155 configure_item_sensitivity (item, etoolbar);
1157 dock = get_dock_nth (etoolbar, tpos);
1158 gtk_widget_set_size_request (dock, -1, -1);
1159 gtk_widget_queue_resize_no_redraw (dock);
1161 toolbar_visibility_refresh (etoolbar);
1165 item_removed_cb (EggToolbarsModel *model,
1166 int toolbar_position,
1168 EggEditableToolbar *etoolbar)
1170 EggEditableToolbarPrivate *priv = etoolbar->priv;
1175 toolbar = get_toolbar_nth (etoolbar, toolbar_position);
1176 item = GTK_WIDGET (gtk_toolbar_get_nth_item
1177 (GTK_TOOLBAR (toolbar), position));
1178 g_return_if_fail (item != NULL);
1180 if (item == priv->selected)
1185 gtk_container_remove (GTK_CONTAINER (toolbar), item);
1187 toolbar_visibility_refresh (etoolbar);
1191 egg_editable_toolbar_build (EggEditableToolbar *etoolbar)
1193 int i, l, n_items, n_toolbars;
1194 EggToolbarsModel *model = etoolbar->priv->model;
1196 g_return_if_fail (model != NULL);
1197 g_return_if_fail (etoolbar->priv->manager != NULL);
1199 n_toolbars = egg_toolbars_model_n_toolbars (model);
1201 for (i = 0; i < n_toolbars; i++)
1203 GtkWidget *toolbar, *dock;
1205 dock = create_dock (etoolbar);
1206 if ((egg_toolbars_model_get_flags (model, i) & EGG_TB_MODEL_HIDDEN) == 0)
1207 gtk_widget_show (dock);
1208 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1209 toolbar = get_toolbar_nth (etoolbar, i);
1211 n_items = egg_toolbars_model_n_items (model, i);
1212 for (l = 0; l < n_items; l++)
1216 item = create_item_from_position (etoolbar, i, l);
1219 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, l);
1221 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1222 configure_item_tooltip (item);
1223 configure_item_sensitivity (item, etoolbar);
1227 egg_toolbars_model_remove_item (model, i, l);
1235 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1239 update_fixed (etoolbar);
1242 for (i = 0; i < n_toolbars; i ++)
1244 toolbar_changed_cb (model, i, etoolbar);
1249 egg_editable_toolbar_disconnect_model (EggEditableToolbar *toolbar)
1251 EggToolbarsModel *model = toolbar->priv->model;
1253 g_signal_handlers_disconnect_by_func
1254 (model, G_CALLBACK (item_added_cb), toolbar);
1255 g_signal_handlers_disconnect_by_func
1256 (model, G_CALLBACK (item_removed_cb), toolbar);
1257 g_signal_handlers_disconnect_by_func
1258 (model, G_CALLBACK (toolbar_added_cb), toolbar);
1259 g_signal_handlers_disconnect_by_func
1260 (model, G_CALLBACK (toolbar_removed_cb), toolbar);
1261 g_signal_handlers_disconnect_by_func
1262 (model, G_CALLBACK (toolbar_changed_cb), toolbar);
1266 egg_editable_toolbar_deconstruct (EggEditableToolbar *toolbar)
1268 EggToolbarsModel *model = toolbar->priv->model;
1271 g_return_if_fail (model != NULL);
1273 if (toolbar->priv->fixed_toolbar)
1275 unset_fixed_style (toolbar);
1276 unparent_fixed (toolbar);
1279 children = gtk_container_get_children (GTK_CONTAINER (toolbar));
1280 g_list_foreach (children, (GFunc) gtk_widget_destroy, NULL);
1281 g_list_free (children);
1285 egg_editable_toolbar_set_model (EggEditableToolbar *etoolbar,
1286 EggToolbarsModel *model)
1288 EggEditableToolbarPrivate *priv = etoolbar->priv;
1290 if (priv->model == model) return;
1294 egg_editable_toolbar_disconnect_model (etoolbar);
1295 egg_editable_toolbar_deconstruct (etoolbar);
1297 g_object_unref (priv->model);
1300 priv->model = g_object_ref (model);
1302 egg_editable_toolbar_build (etoolbar);
1304 toolbar_visibility_refresh (etoolbar);
1306 g_signal_connect (model, "item_added",
1307 G_CALLBACK (item_added_cb), etoolbar);
1308 g_signal_connect (model, "item_removed",
1309 G_CALLBACK (item_removed_cb), etoolbar);
1310 g_signal_connect (model, "toolbar_added",
1311 G_CALLBACK (toolbar_added_cb), etoolbar);
1312 g_signal_connect (model, "toolbar_removed",
1313 G_CALLBACK (toolbar_removed_cb), etoolbar);
1314 g_signal_connect (model, "toolbar_changed",
1315 G_CALLBACK (toolbar_changed_cb), etoolbar);
1319 egg_editable_toolbar_init (EggEditableToolbar *etoolbar)
1321 EggEditableToolbarPrivate *priv;
1323 priv = etoolbar->priv = EGG_EDITABLE_TOOLBAR_GET_PRIVATE (etoolbar);
1325 priv->save_hidden = TRUE;
1327 g_signal_connect (etoolbar, "notify::visible",
1328 G_CALLBACK (toolbar_visibility_refresh), NULL);
1332 egg_editable_toolbar_dispose (GObject *object)
1334 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1335 EggEditableToolbarPrivate *priv = etoolbar->priv;
1338 if (priv->fixed_toolbar != NULL)
1340 g_object_unref (priv->fixed_toolbar);
1341 priv->fixed_toolbar = NULL;
1344 if (priv->visibility_paths)
1346 children = priv->visibility_paths;
1347 g_list_foreach (children, (GFunc) g_free, NULL);
1348 g_list_free (children);
1349 priv->visibility_paths = NULL;
1352 g_free (priv->popup_path);
1353 priv->popup_path = NULL;
1355 if (priv->manager != NULL)
1357 if (priv->visibility_id)
1359 gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
1360 priv->visibility_id = 0;
1363 g_object_unref (priv->manager);
1364 priv->manager = NULL;
1369 egg_editable_toolbar_disconnect_model (etoolbar);
1370 g_object_unref (priv->model);
1374 G_OBJECT_CLASS (egg_editable_toolbar_parent_class)->dispose (object);
1378 egg_editable_toolbar_set_ui_manager (EggEditableToolbar *etoolbar,
1379 GtkUIManager *manager)
1381 static const GtkActionEntry actions[] = {
1382 { "MoveToolItem", STOCK_DRAG_MODE, N_("_Move on Toolbar"), NULL,
1383 N_("Move the selected item on the toolbar"), G_CALLBACK (move_item_cb) },
1384 { "RemoveToolItem", GTK_STOCK_REMOVE, N_("_Remove from Toolbar"), NULL,
1385 N_("Remove the selected item from the toolbar"), G_CALLBACK (remove_item_cb) },
1386 { "RemoveToolbar", GTK_STOCK_DELETE, N_("_Delete Toolbar"), NULL,
1387 N_("Remove the selected toolbar"), G_CALLBACK (remove_toolbar_cb) },
1390 etoolbar->priv->manager = g_object_ref (manager);
1392 etoolbar->priv->actions = gtk_action_group_new ("ToolbarActions");
1393 gtk_action_group_set_translation_domain (etoolbar->priv->actions, GETTEXT_PACKAGE);
1394 gtk_action_group_add_actions (etoolbar->priv->actions, actions,
1395 G_N_ELEMENTS (actions), etoolbar);
1396 gtk_ui_manager_insert_action_group (manager, etoolbar->priv->actions, -1);
1397 g_object_unref (etoolbar->priv->actions);
1399 toolbar_visibility_refresh (etoolbar);
1402 GtkWidget * egg_editable_toolbar_get_selected (EggEditableToolbar *etoolbar)
1404 return etoolbar->priv->selected;
1408 egg_editable_toolbar_set_selected (EggEditableToolbar *etoolbar,
1411 GtkWidget *toolbar, *toolitem;
1414 etoolbar->priv->selected = widget;
1416 toolbar = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR) : NULL;
1417 toolitem = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM) : NULL;
1421 gint tpos = get_toolbar_position (etoolbar, toolbar);
1422 editable = ((egg_toolbars_model_get_flags (etoolbar->priv->model, tpos) & EGG_TB_MODEL_NOT_EDITABLE) == 0);
1429 gtk_action_set_visible (find_action (etoolbar, "RemoveToolbar"), (toolbar != NULL) && (etoolbar->priv->edit_mode > 0));
1430 gtk_action_set_visible (find_action (etoolbar, "RemoveToolItem"), (toolitem != NULL) && editable);
1431 gtk_action_set_visible (find_action (etoolbar, "MoveToolItem"), (toolitem != NULL) && editable);
1435 set_edit_mode (EggEditableToolbar *etoolbar,
1438 EggEditableToolbarPrivate *priv = etoolbar->priv;
1441 i = priv->edit_mode;
1448 g_return_if_fail (priv->edit_mode > 0);
1451 i *= priv->edit_mode;
1455 for (i = get_n_toolbars (etoolbar)-1; i >= 0; i--)
1459 toolbar = get_toolbar_nth (etoolbar, i);
1460 n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
1462 if (n_items == 0 && priv->edit_mode == 0)
1464 egg_toolbars_model_remove_toolbar (priv->model, i);
1468 for (l = 0; l < n_items; l++)
1472 item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
1474 configure_item_cursor (item, etoolbar);
1475 configure_item_sensitivity (item, etoolbar);
1483 egg_editable_toolbar_set_property (GObject *object,
1485 const GValue *value,
1488 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1492 case PROP_UI_MANAGER:
1493 egg_editable_toolbar_set_ui_manager (etoolbar, g_value_get_object (value));
1495 case PROP_TOOLBARS_MODEL:
1496 egg_editable_toolbar_set_model (etoolbar, g_value_get_object (value));
1499 egg_editable_toolbar_set_selected (etoolbar, g_value_get_object (value));
1501 case PROP_POPUP_PATH:
1502 etoolbar->priv->popup_path = g_strdup (g_value_get_string (value));
1504 case PROP_EDIT_MODE:
1505 set_edit_mode (etoolbar, g_value_get_boolean (value));
1508 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1514 egg_editable_toolbar_get_property (GObject *object,
1519 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1523 case PROP_UI_MANAGER:
1524 g_value_set_object (value, etoolbar->priv->manager);
1526 case PROP_TOOLBARS_MODEL:
1527 g_value_set_object (value, etoolbar->priv->model);
1530 g_value_set_object (value, etoolbar->priv->selected);
1532 case PROP_EDIT_MODE:
1533 g_value_set_boolean (value, etoolbar->priv->edit_mode>0);
1536 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1542 egg_editable_toolbar_class_init (EggEditableToolbarClass *klass)
1544 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1546 object_class->dispose = egg_editable_toolbar_dispose;
1547 object_class->set_property = egg_editable_toolbar_set_property;
1548 object_class->get_property = egg_editable_toolbar_get_property;
1550 egg_editable_toolbar_signals[ACTION_REQUEST] =
1551 g_signal_new ("action_request",
1552 G_OBJECT_CLASS_TYPE (object_class),
1554 G_STRUCT_OFFSET (EggEditableToolbarClass, action_request),
1555 NULL, NULL, g_cclosure_marshal_VOID__STRING,
1556 G_TYPE_NONE, 1, G_TYPE_STRING);
1558 g_object_class_install_property (object_class,
1560 g_param_spec_object ("ui-manager",
1563 GTK_TYPE_UI_MANAGER,
1564 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1565 g_object_class_install_property (object_class,
1566 PROP_TOOLBARS_MODEL,
1567 g_param_spec_object ("model",
1570 EGG_TYPE_TOOLBARS_MODEL,
1571 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1572 g_object_class_install_property (object_class,
1574 g_param_spec_object ("selected",
1576 "Selected toolitem",
1578 G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1580 g_object_class_install_property (object_class,
1582 g_param_spec_string ("popup-path",
1586 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1588 g_object_class_install_property (object_class,
1590 g_param_spec_boolean ("edit-mode",
1594 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1596 g_type_class_add_private (object_class, sizeof (EggEditableToolbarPrivate));
1600 egg_editable_toolbar_new (GtkUIManager *manager,
1601 const char *popup_path)
1603 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1604 "ui-manager", manager,
1605 "popup-path", popup_path,
1610 egg_editable_toolbar_new_with_model (GtkUIManager *manager,
1611 EggToolbarsModel *model,
1612 const char *popup_path)
1614 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1615 "ui-manager", manager,
1617 "popup-path", popup_path,
1622 egg_editable_toolbar_get_edit_mode (EggEditableToolbar *etoolbar)
1624 EggEditableToolbarPrivate *priv = etoolbar->priv;
1626 return priv->edit_mode > 0;
1630 egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar,
1633 set_edit_mode (etoolbar, mode);
1634 g_object_notify (G_OBJECT (etoolbar), "edit-mode");
1638 egg_editable_toolbar_add_visibility (EggEditableToolbar *etoolbar,
1641 etoolbar->priv->visibility_paths = g_list_prepend
1642 (etoolbar->priv->visibility_paths, g_strdup (path));
1646 egg_editable_toolbar_show (EggEditableToolbar *etoolbar,
1649 EggEditableToolbarPrivate *priv = etoolbar->priv;
1650 EggToolbarsModel *model = priv->model;
1653 n_toolbars = egg_toolbars_model_n_toolbars (model);
1654 for (i = 0; i < n_toolbars; i++)
1656 const char *toolbar_name;
1658 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1659 if (strcmp (toolbar_name, name) == 0)
1661 gtk_widget_show (get_dock_nth (etoolbar, i));
1667 egg_editable_toolbar_hide (EggEditableToolbar *etoolbar,
1670 EggEditableToolbarPrivate *priv = etoolbar->priv;
1671 EggToolbarsModel *model = priv->model;
1674 n_toolbars = egg_toolbars_model_n_toolbars (model);
1675 for (i = 0; i < n_toolbars; i++)
1677 const char *toolbar_name;
1679 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1680 if (strcmp (toolbar_name, name) == 0)
1682 gtk_widget_hide (get_dock_nth (etoolbar, i));
1688 egg_editable_toolbar_set_fixed (EggEditableToolbar *etoolbar,
1689 GtkToolbar *toolbar)
1691 EggEditableToolbarPrivate *priv = etoolbar->priv;
1693 g_return_if_fail (!toolbar || GTK_IS_TOOLBAR (toolbar));
1695 if (priv->fixed_toolbar)
1697 unparent_fixed (etoolbar);
1698 g_object_unref (priv->fixed_toolbar);
1699 priv->fixed_toolbar = NULL;
1704 priv->fixed_toolbar = GTK_WIDGET (toolbar);
1705 gtk_toolbar_set_show_arrow (toolbar, FALSE);
1706 g_object_ref_sink (toolbar);
1709 update_fixed (etoolbar);
1712 #define DEFAULT_ICON_HEIGHT 20
1713 #define DEFAULT_ICON_WIDTH 0
1716 fake_expose_widget (GtkWidget *widget,
1719 GdkWindow *tmp_window;
1720 GdkEventExpose event;
1722 event.type = GDK_EXPOSE;
1723 event.window = pixmap;
1724 event.send_event = FALSE;
1725 event.area = widget->allocation;
1726 event.region = NULL;
1729 tmp_window = widget->window;
1730 widget->window = pixmap;
1731 gtk_widget_send_expose (widget, (GdkEvent *) &event);
1732 widget->window = tmp_window;
1735 /* We should probably experiment some more with this.
1736 * Right now the rendered icon is pretty good for most
1737 * themes. However, the icon is slightly large for themes
1738 * with large toolbar icons.
1741 new_pixbuf_from_widget (GtkWidget *widget)
1745 GtkRequisition requisition;
1746 GtkAllocation allocation;
1753 icon_width = DEFAULT_ICON_WIDTH;
1755 screen = gtk_widget_get_screen (widget);
1757 if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen),
1758 GTK_ICON_SIZE_LARGE_TOOLBAR,
1762 icon_height = DEFAULT_ICON_HEIGHT;
1765 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1767 gtk_container_add (GTK_CONTAINER (window), widget);
1768 gtk_widget_realize (window);
1769 gtk_widget_show (widget);
1770 gtk_widget_realize (widget);
1771 gtk_widget_map (widget);
1773 /* Gtk will never set the width or height of a window to 0. So setting the width to
1774 * 0 and than getting it will provide us with the minimum width needed to render
1775 * the icon correctly, without any additional window background noise.
1776 * This is needed mostly for pixmap based themes.
1778 gtk_window_set_default_size (GTK_WINDOW (window), icon_width, icon_height);
1779 gtk_window_get_size (GTK_WINDOW (window),&icon_width, &icon_height);
1781 gtk_widget_size_request (window, &requisition);
1784 allocation.width = icon_width;
1785 allocation.height = icon_height;
1786 gtk_widget_size_allocate (window, &allocation);
1787 gtk_widget_size_request (window, &requisition);
1789 /* Create a pixmap */
1790 visual = gtk_widget_get_visual (window);
1791 pixmap = gdk_pixmap_new (NULL, icon_width, icon_height, visual->depth);
1792 gdk_drawable_set_colormap (GDK_DRAWABLE (pixmap), gtk_widget_get_colormap (window));
1794 /* Draw the window */
1795 gtk_widget_ensure_style (window);
1796 g_assert (window->style);
1797 g_assert (window->style->font_desc);
1799 fake_expose_widget (window, pixmap);
1800 fake_expose_widget (widget, pixmap);
1802 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, icon_width, icon_height);
1803 gdk_pixbuf_get_from_drawable (pixbuf, pixmap, NULL, 0, 0, 0, 0, icon_width, icon_height);
1805 gtk_widget_destroy (window);
1811 new_separator_pixbuf ()
1813 GtkWidget *separator;
1816 separator = gtk_vseparator_new ();
1817 pixbuf = new_pixbuf_from_widget (separator);
1822 update_separator_image (GtkImage *image)
1824 GdkPixbuf *pixbuf = new_separator_pixbuf ();
1825 gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
1826 g_object_unref (pixbuf);
1830 style_set_cb (GtkWidget *widget,
1831 GtkStyle *previous_style,
1835 update_separator_image (image);
1840 _egg_editable_toolbar_new_separator_image (void)
1842 GtkWidget *image = gtk_image_new ();
1843 update_separator_image (GTK_IMAGE (image));
1844 g_signal_connect (G_OBJECT (image), "style_set",
1845 G_CALLBACK (style_set_cb), GTK_IMAGE (image));
1851 egg_editable_toolbar_get_model (EggEditableToolbar *etoolbar)
1853 return etoolbar->priv->model;