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 = gtk_widget_get_action (widget);
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 = gtk_widget_get_action (widget);
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 = gtk_widget_get_action (GTK_WIDGET (item));
504 g_object_notify (G_OBJECT (action), "tooltip");
510 connect_widget_signals (GtkWidget *proxy, EggEditableToolbar *etoolbar)
512 if (GTK_IS_CONTAINER (proxy))
514 gtk_container_forall (GTK_CONTAINER (proxy),
515 (GtkCallback) connect_widget_signals,
516 (gpointer) etoolbar);
519 if (GTK_IS_TOOL_ITEM (proxy))
521 g_signal_connect_object (proxy, "drag_begin",
522 G_CALLBACK (drag_begin_cb),
524 g_signal_connect_object (proxy, "drag_end",
525 G_CALLBACK (drag_end_cb),
527 g_signal_connect_object (proxy, "drag_data_get",
528 G_CALLBACK (drag_data_get_cb),
530 g_signal_connect_object (proxy, "drag_data_delete",
531 G_CALLBACK (drag_data_delete_cb),
535 if (GTK_IS_BUTTON (proxy) || GTK_IS_TOOL_ITEM (proxy))
537 g_signal_connect_object (proxy, "button-press-event",
538 G_CALLBACK (button_press_event_cb),
544 action_sensitive_cb (GtkAction *action,
548 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR
549 (gtk_widget_get_ancestor (GTK_WIDGET (item), EGG_TYPE_EDITABLE_TOOLBAR));
551 if (etoolbar->priv->edit_mode > 0)
553 gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
558 create_item_from_action (EggEditableToolbar *etoolbar,
563 g_return_val_if_fail (name != NULL, NULL);
565 if (strcmp (name, "_separator") == 0)
567 item = gtk_separator_tool_item_new ();
571 GtkAction *action = find_action (etoolbar, name);
572 if (action == NULL) return NULL;
574 item = GTK_TOOL_ITEM (gtk_action_create_tool_item (action));
576 /* Normally done on-demand by the GtkUIManager, but no
577 * such demand may have been made yet, so do it ourselves.
579 gtk_action_set_accel_group
580 (action, gtk_ui_manager_get_accel_group(etoolbar->priv->manager));
582 g_signal_connect_object (action, "notify::sensitive",
583 G_CALLBACK (action_sensitive_cb), item, 0);
586 gtk_widget_show (GTK_WIDGET (item));
588 g_object_set_data_full (G_OBJECT (item), EGG_ITEM_NAME,
589 g_strdup (name), g_free);
595 create_item_from_position (EggEditableToolbar *etoolbar,
596 int toolbar_position,
602 name = egg_toolbars_model_item_nth (etoolbar->priv->model, toolbar_position, position);
603 item = create_item_from_action (etoolbar, name);
609 toolbar_drag_data_received_cb (GtkToolbar *toolbar,
610 GdkDragContext *context,
613 GtkSelectionData *selection_data,
616 EggEditableToolbar *etoolbar)
618 /* This function can be called for two reasons
620 * (1) drag_motion() needs an item to pass to
621 * gtk_toolbar_set_drop_highlight_item(). We can
622 * recognize this case by etoolbar->priv->pending being TRUE
623 * We should just create an item and return.
625 * (2) The drag has finished, and drag_drop() wants us to
626 * actually add a new item to the toolbar.
629 GdkAtom type = selection_data->type;
630 const char *data = (char *)selection_data->data;
634 gboolean used = FALSE;
636 /* Find out where the drop is occuring, and the name of what is being dropped. */
637 if (selection_data->length >= 0)
639 ipos = gtk_toolbar_get_drop_index (toolbar, x, y);
640 name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, FALSE);
643 used = ((egg_toolbars_model_get_name_flags (etoolbar->priv->model, name) & EGG_TB_MODEL_NAME_USED) != 0);
647 /* If we just want a highlight item, then . */
648 if (etoolbar->priv->dnd_pending > 0)
650 etoolbar->priv->dnd_pending--;
652 if (name != NULL && etoolbar->priv->dnd_toolbar == toolbar && !used)
654 etoolbar->priv->dnd_toolitem = create_item_from_action (etoolbar, name);
655 gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar,
656 etoolbar->priv->dnd_toolitem, ipos);
661 gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
662 etoolbar->priv->dnd_toolbar = NULL;
663 etoolbar->priv->dnd_toolitem = NULL;
665 /* If we don't have a name to use yet, try to create one. */
666 if (name == NULL && selection_data->length >= 0)
668 name = egg_toolbars_model_get_name (etoolbar->priv->model, type, data, TRUE);
671 if (name != NULL && !used)
673 gint tpos = get_toolbar_position (etoolbar, GTK_WIDGET (toolbar));
674 egg_toolbars_model_add_item (etoolbar->priv->model, tpos, ipos, name);
675 gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time);
679 gtk_drag_finish (context, FALSE, context->action == GDK_ACTION_MOVE, time);
687 toolbar_drag_drop_cb (GtkToolbar *toolbar,
688 GdkDragContext *context,
692 EggEditableToolbar *etoolbar)
696 target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL);
697 if (target != GDK_NONE)
699 gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
707 toolbar_drag_motion_cb (GtkToolbar *toolbar,
708 GdkDragContext *context,
712 EggEditableToolbar *etoolbar)
714 GdkAtom target = gtk_drag_dest_find_target (GTK_WIDGET (toolbar), context, NULL);
715 if (target == GDK_NONE)
717 gdk_drag_status (context, 0, time);
721 /* Make ourselves the current dnd toolbar, and request a highlight item. */
722 if (etoolbar->priv->dnd_toolbar != toolbar)
724 etoolbar->priv->dnd_toolbar = toolbar;
725 etoolbar->priv->dnd_toolitem = NULL;
726 etoolbar->priv->dnd_pending++;
727 gtk_drag_get_data (GTK_WIDGET (toolbar), context, target, time);
730 /* If a highlight item is available, use it. */
731 else if (etoolbar->priv->dnd_toolitem)
733 gint ipos = gtk_toolbar_get_drop_index (etoolbar->priv->dnd_toolbar, x, y);
734 gtk_toolbar_set_drop_highlight_item (etoolbar->priv->dnd_toolbar,
735 etoolbar->priv->dnd_toolitem, ipos);
738 gdk_drag_status (context, context->suggested_action, time);
744 toolbar_drag_leave_cb (GtkToolbar *toolbar,
745 GdkDragContext *context,
747 EggEditableToolbar *etoolbar)
749 gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
751 /* If we were the current dnd toolbar target, remove the item. */
752 if (etoolbar->priv->dnd_toolbar == toolbar)
754 etoolbar->priv->dnd_toolbar = NULL;
755 etoolbar->priv->dnd_toolitem = NULL;
760 configure_drag_dest (EggEditableToolbar *etoolbar,
763 EggToolbarsItemType *type;
764 GtkTargetList *targets;
767 /* Make every toolbar able to receive drag-drops. */
768 gtk_drag_dest_set (GTK_WIDGET (toolbar), 0,
769 dest_drag_types, G_N_ELEMENTS (dest_drag_types),
770 GDK_ACTION_MOVE | GDK_ACTION_COPY);
772 /* Add any specialist drag-drop abilities. */
773 targets = gtk_drag_dest_get_target_list (GTK_WIDGET (toolbar));
774 list = egg_toolbars_model_get_types (etoolbar->priv->model);
778 if (type->new_name != NULL || type->get_name != NULL)
779 gtk_target_list_add (targets, type->type, 0, 0);
785 toggled_visibility_cb (GtkToggleAction *action,
786 EggEditableToolbar *etoolbar)
788 EggEditableToolbarPrivate *priv = etoolbar->priv;
790 EggTbModelFlags flags;
794 visible = gtk_toggle_action_get_active (action);
795 for (i = 0; i < priv->visibility_actions->len; i++)
796 if (g_ptr_array_index (priv->visibility_actions, i) == action)
799 g_return_if_fail (i < priv->visibility_actions->len);
801 dock = get_dock_nth (etoolbar, i);
804 gtk_widget_show (dock);
808 gtk_widget_hide (dock);
811 if (priv->save_hidden)
813 flags = egg_toolbars_model_get_flags (priv->model, i);
817 flags &= ~(EGG_TB_MODEL_HIDDEN);
821 flags |= (EGG_TB_MODEL_HIDDEN);
824 egg_toolbars_model_set_flags (priv->model, i, flags);
829 toolbar_visibility_refresh (EggEditableToolbar *etoolbar)
831 EggEditableToolbarPrivate *priv = etoolbar->priv;
832 gint n_toolbars, n_items, i, j, k;
833 GtkToggleAction *action;
837 char action_name[40];
841 if (priv == NULL || priv->model == NULL || priv->manager == NULL ||
842 priv->visibility_paths == NULL || priv->actions == NULL)
847 if (priv->visibility_actions == NULL)
849 priv->visibility_actions = g_ptr_array_new ();
852 if (priv->visibility_id != 0)
854 gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
857 priv->visibility_id = gtk_ui_manager_new_merge_id (priv->manager);
859 showing = GTK_WIDGET_VISIBLE (etoolbar);
861 n_toolbars = egg_toolbars_model_n_toolbars (priv->model);
862 for (i = 0; i < n_toolbars; i++)
864 string = g_string_sized_new (0);
865 n_items = egg_toolbars_model_n_items (priv->model, i);
866 for (k = 0, j = 0; j < n_items; j++)
868 GValue value = { 0, };
872 name = egg_toolbars_model_item_nth (priv->model, i, j);
873 if (name == NULL) continue;
874 action = find_action (etoolbar, name);
875 if (action == NULL) continue;
877 g_value_init (&value, G_TYPE_STRING);
878 g_object_get_property (G_OBJECT (action), "label", &value);
879 name = g_value_get_string (&value);
882 g_value_unset (&value);
885 k += g_utf8_strlen (name, -1) + 2;
888 g_string_append (string, ", ");
891 g_value_unset (&value);
895 g_string_append (string, name);
896 g_value_unset (&value);
900 g_string_append (string, " ...");
903 tmp = g_string_free (string, FALSE);
904 for (j = 0, k = 0; tmp[j]; j++)
906 if (tmp[j] == '_') continue;
911 /* Translaters: This string is for a toggle to display a toolbar.
912 * The name of the toolbar is automatically computed from the widgets
913 * on the toolbar, and is placed at the %s. Note the _ before the %s
914 * which is used to add mnemonics. We know that this is likely to
915 * produce duplicates, but don't worry about it. If your language
916 * normally has a mnemonic at the start, please use the _. If not,
918 action_label = g_strdup_printf (_("Show “_%s”"), tmp);
921 sprintf(action_name, "ToolbarToggle%d", i);
923 if (i >= priv->visibility_actions->len)
925 action = gtk_toggle_action_new (action_name, action_label, NULL, NULL);
926 g_ptr_array_add (priv->visibility_actions, action);
927 g_signal_connect_object (action, "toggled",
928 G_CALLBACK (toggled_visibility_cb),
930 gtk_action_group_add_action (priv->actions, GTK_ACTION (action));
934 action = g_ptr_array_index (priv->visibility_actions, i);
935 g_object_set (action, "label", action_label, NULL);
938 gtk_action_set_visible (GTK_ACTION (action), (egg_toolbars_model_get_flags (priv->model, i)
939 & EGG_TB_MODEL_NOT_REMOVABLE) == 0);
940 gtk_action_set_sensitive (GTK_ACTION (action), showing);
941 gtk_toggle_action_set_active (action, GTK_WIDGET_VISIBLE
942 (get_dock_nth (etoolbar, i)));
944 for (list = priv->visibility_paths; list != NULL; list = g_list_next (list))
946 gtk_ui_manager_add_ui (priv->manager, priv->visibility_id,
947 (const char *)list->data, action_name, action_name,
948 GTK_UI_MANAGER_MENUITEM, FALSE);
951 g_free (action_label);
954 gtk_ui_manager_ensure_update (priv->manager);
956 while (i < priv->visibility_actions->len)
958 action = g_ptr_array_index (priv->visibility_actions, i);
959 g_ptr_array_remove_index_fast (priv->visibility_actions, i);
960 gtk_action_group_remove_action (priv->actions, GTK_ACTION (action));
966 create_dock (EggEditableToolbar *etoolbar)
968 GtkWidget *toolbar, *hbox;
970 hbox = gtk_hbox_new (0, FALSE);
972 toolbar = gtk_toolbar_new ();
973 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
974 gtk_widget_show (toolbar);
975 gtk_box_pack_start (GTK_BOX (hbox), toolbar, TRUE, TRUE, 0);
977 g_signal_connect (toolbar, "drag_drop",
978 G_CALLBACK (toolbar_drag_drop_cb), etoolbar);
979 g_signal_connect (toolbar, "drag_motion",
980 G_CALLBACK (toolbar_drag_motion_cb), etoolbar);
981 g_signal_connect (toolbar, "drag_leave",
982 G_CALLBACK (toolbar_drag_leave_cb), etoolbar);
984 g_signal_connect (toolbar, "drag_data_received",
985 G_CALLBACK (toolbar_drag_data_received_cb), etoolbar);
986 g_signal_connect (toolbar, "popup_context_menu",
987 G_CALLBACK (popup_context_menu_cb), etoolbar);
989 configure_drag_dest (etoolbar, GTK_TOOLBAR (toolbar));
995 set_fixed_style (EggEditableToolbar *t, GtkToolbarStyle style)
997 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
998 gtk_toolbar_set_style (GTK_TOOLBAR (t->priv->fixed_toolbar),
999 style == GTK_TOOLBAR_ICONS ? GTK_TOOLBAR_BOTH_HORIZ : style);
1003 unset_fixed_style (EggEditableToolbar *t)
1005 g_return_if_fail (GTK_IS_TOOLBAR (t->priv->fixed_toolbar));
1006 gtk_toolbar_unset_style (GTK_TOOLBAR (t->priv->fixed_toolbar));
1010 toolbar_changed_cb (EggToolbarsModel *model,
1012 EggEditableToolbar *etoolbar)
1015 EggTbModelFlags flags;
1016 GtkToolbarStyle style;
1018 flags = egg_toolbars_model_get_flags (model, position);
1019 toolbar = get_toolbar_nth (etoolbar, position);
1021 if (flags & EGG_TB_MODEL_ICONS)
1023 style = GTK_TOOLBAR_ICONS;
1025 else if (flags & EGG_TB_MODEL_TEXT)
1027 style = GTK_TOOLBAR_TEXT;
1029 else if (flags & EGG_TB_MODEL_BOTH)
1031 style = GTK_TOOLBAR_BOTH;
1033 else if (flags & EGG_TB_MODEL_BOTH_HORIZ)
1035 style = GTK_TOOLBAR_BOTH_HORIZ;
1039 gtk_toolbar_unset_style (GTK_TOOLBAR (toolbar));
1040 if (position == 0 && etoolbar->priv->fixed_toolbar)
1042 unset_fixed_style (etoolbar);
1047 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style);
1048 if (position == 0 && etoolbar->priv->fixed_toolbar)
1050 set_fixed_style (etoolbar, style);
1053 toolbar_visibility_refresh (etoolbar);
1057 unparent_fixed (EggEditableToolbar *etoolbar)
1059 GtkWidget *toolbar, *dock;
1060 g_return_if_fail (GTK_IS_TOOLBAR (etoolbar->priv->fixed_toolbar));
1062 toolbar = etoolbar->priv->fixed_toolbar;
1063 dock = get_dock_nth (etoolbar, 0);
1065 if (dock && toolbar->parent != NULL)
1067 gtk_container_remove (GTK_CONTAINER (dock), toolbar);
1072 update_fixed (EggEditableToolbar *etoolbar)
1074 GtkWidget *toolbar, *dock;
1075 if (!etoolbar->priv->fixed_toolbar) return;
1077 toolbar = etoolbar->priv->fixed_toolbar;
1078 dock = get_dock_nth (etoolbar, 0);
1080 if (dock && toolbar && toolbar->parent == NULL)
1082 gtk_box_pack_end (GTK_BOX (dock), toolbar, FALSE, TRUE, 0);
1084 gtk_widget_show (toolbar);
1086 gtk_widget_set_size_request (dock, -1, -1);
1087 gtk_widget_queue_resize_no_redraw (dock);
1092 toolbar_added_cb (EggToolbarsModel *model,
1094 EggEditableToolbar *etoolbar)
1098 dock = create_dock (etoolbar);
1099 if ((egg_toolbars_model_get_flags (model, position) & EGG_TB_MODEL_HIDDEN) == 0)
1100 gtk_widget_show (dock);
1102 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1104 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1106 gtk_box_reorder_child (GTK_BOX (etoolbar), dock, position);
1108 gtk_widget_show_all (dock);
1110 update_fixed (etoolbar);
1112 toolbar_visibility_refresh (etoolbar);
1116 toolbar_removed_cb (EggToolbarsModel *model,
1118 EggEditableToolbar *etoolbar)
1122 if (position == 0 && etoolbar->priv->fixed_toolbar != NULL)
1124 unparent_fixed (etoolbar);
1127 dock = get_dock_nth (etoolbar, position);
1128 gtk_widget_destroy (dock);
1130 update_fixed (etoolbar);
1132 toolbar_visibility_refresh (etoolbar);
1136 item_added_cb (EggToolbarsModel *model,
1139 EggEditableToolbar *etoolbar)
1145 toolbar = get_toolbar_nth (etoolbar, tpos);
1146 item = create_item_from_position (etoolbar, tpos, ipos);
1147 if (item == NULL) return;
1149 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, ipos);
1151 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1152 configure_item_tooltip (item);
1153 configure_item_cursor (item, etoolbar);
1154 configure_item_sensitivity (item, etoolbar);
1156 dock = get_dock_nth (etoolbar, tpos);
1157 gtk_widget_set_size_request (dock, -1, -1);
1158 gtk_widget_queue_resize_no_redraw (dock);
1160 toolbar_visibility_refresh (etoolbar);
1164 item_removed_cb (EggToolbarsModel *model,
1165 int toolbar_position,
1167 EggEditableToolbar *etoolbar)
1169 EggEditableToolbarPrivate *priv = etoolbar->priv;
1174 toolbar = get_toolbar_nth (etoolbar, toolbar_position);
1175 item = GTK_WIDGET (gtk_toolbar_get_nth_item
1176 (GTK_TOOLBAR (toolbar), position));
1177 g_return_if_fail (item != NULL);
1179 if (item == priv->selected)
1184 gtk_container_remove (GTK_CONTAINER (toolbar), item);
1186 toolbar_visibility_refresh (etoolbar);
1190 egg_editable_toolbar_build (EggEditableToolbar *etoolbar)
1192 int i, l, n_items, n_toolbars;
1193 EggToolbarsModel *model = etoolbar->priv->model;
1195 g_return_if_fail (model != NULL);
1196 g_return_if_fail (etoolbar->priv->manager != NULL);
1198 n_toolbars = egg_toolbars_model_n_toolbars (model);
1200 for (i = 0; i < n_toolbars; i++)
1202 GtkWidget *toolbar, *dock;
1204 dock = create_dock (etoolbar);
1205 if ((egg_toolbars_model_get_flags (model, i) & EGG_TB_MODEL_HIDDEN) == 0)
1206 gtk_widget_show (dock);
1207 gtk_box_pack_start (GTK_BOX (etoolbar), dock, TRUE, TRUE, 0);
1208 toolbar = get_toolbar_nth (etoolbar, i);
1210 n_items = egg_toolbars_model_n_items (model, i);
1211 for (l = 0; l < n_items; l++)
1215 item = create_item_from_position (etoolbar, i, l);
1218 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, l);
1220 connect_widget_signals (GTK_WIDGET (item), etoolbar);
1221 configure_item_tooltip (item);
1222 configure_item_sensitivity (item, etoolbar);
1226 egg_toolbars_model_remove_item (model, i, l);
1234 gtk_widget_set_size_request (dock, -1, MIN_TOOLBAR_HEIGHT);
1238 update_fixed (etoolbar);
1241 for (i = 0; i < n_toolbars; i ++)
1243 toolbar_changed_cb (model, i, etoolbar);
1248 egg_editable_toolbar_disconnect_model (EggEditableToolbar *toolbar)
1250 EggToolbarsModel *model = toolbar->priv->model;
1252 g_signal_handlers_disconnect_by_func
1253 (model, G_CALLBACK (item_added_cb), toolbar);
1254 g_signal_handlers_disconnect_by_func
1255 (model, G_CALLBACK (item_removed_cb), toolbar);
1256 g_signal_handlers_disconnect_by_func
1257 (model, G_CALLBACK (toolbar_added_cb), toolbar);
1258 g_signal_handlers_disconnect_by_func
1259 (model, G_CALLBACK (toolbar_removed_cb), toolbar);
1260 g_signal_handlers_disconnect_by_func
1261 (model, G_CALLBACK (toolbar_changed_cb), toolbar);
1265 egg_editable_toolbar_deconstruct (EggEditableToolbar *toolbar)
1267 EggToolbarsModel *model = toolbar->priv->model;
1270 g_return_if_fail (model != NULL);
1272 if (toolbar->priv->fixed_toolbar)
1274 unset_fixed_style (toolbar);
1275 unparent_fixed (toolbar);
1278 children = gtk_container_get_children (GTK_CONTAINER (toolbar));
1279 g_list_foreach (children, (GFunc) gtk_widget_destroy, NULL);
1280 g_list_free (children);
1284 egg_editable_toolbar_set_model (EggEditableToolbar *etoolbar,
1285 EggToolbarsModel *model)
1287 EggEditableToolbarPrivate *priv = etoolbar->priv;
1289 if (priv->model == model) return;
1293 egg_editable_toolbar_disconnect_model (etoolbar);
1294 egg_editable_toolbar_deconstruct (etoolbar);
1296 g_object_unref (priv->model);
1299 priv->model = g_object_ref (model);
1301 egg_editable_toolbar_build (etoolbar);
1303 toolbar_visibility_refresh (etoolbar);
1305 g_signal_connect (model, "item_added",
1306 G_CALLBACK (item_added_cb), etoolbar);
1307 g_signal_connect (model, "item_removed",
1308 G_CALLBACK (item_removed_cb), etoolbar);
1309 g_signal_connect (model, "toolbar_added",
1310 G_CALLBACK (toolbar_added_cb), etoolbar);
1311 g_signal_connect (model, "toolbar_removed",
1312 G_CALLBACK (toolbar_removed_cb), etoolbar);
1313 g_signal_connect (model, "toolbar_changed",
1314 G_CALLBACK (toolbar_changed_cb), etoolbar);
1318 egg_editable_toolbar_init (EggEditableToolbar *etoolbar)
1320 EggEditableToolbarPrivate *priv;
1322 priv = etoolbar->priv = EGG_EDITABLE_TOOLBAR_GET_PRIVATE (etoolbar);
1324 priv->save_hidden = TRUE;
1326 g_signal_connect (etoolbar, "notify::visible",
1327 G_CALLBACK (toolbar_visibility_refresh), NULL);
1331 egg_editable_toolbar_dispose (GObject *object)
1333 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1334 EggEditableToolbarPrivate *priv = etoolbar->priv;
1337 if (priv->fixed_toolbar != NULL)
1339 g_object_unref (priv->fixed_toolbar);
1340 priv->fixed_toolbar = NULL;
1343 if (priv->visibility_paths)
1345 children = priv->visibility_paths;
1346 g_list_foreach (children, (GFunc) g_free, NULL);
1347 g_list_free (children);
1348 priv->visibility_paths = NULL;
1351 g_free (priv->popup_path);
1352 priv->popup_path = NULL;
1354 if (priv->manager != NULL)
1356 if (priv->visibility_id)
1358 gtk_ui_manager_remove_ui (priv->manager, priv->visibility_id);
1359 priv->visibility_id = 0;
1362 g_object_unref (priv->manager);
1363 priv->manager = NULL;
1368 egg_editable_toolbar_disconnect_model (etoolbar);
1369 g_object_unref (priv->model);
1373 G_OBJECT_CLASS (egg_editable_toolbar_parent_class)->dispose (object);
1377 egg_editable_toolbar_set_ui_manager (EggEditableToolbar *etoolbar,
1378 GtkUIManager *manager)
1380 static const GtkActionEntry actions[] = {
1381 { "MoveToolItem", STOCK_DRAG_MODE, N_("_Move on Toolbar"), NULL,
1382 N_("Move the selected item on the toolbar"), G_CALLBACK (move_item_cb) },
1383 { "RemoveToolItem", GTK_STOCK_REMOVE, N_("_Remove from Toolbar"), NULL,
1384 N_("Remove the selected item from the toolbar"), G_CALLBACK (remove_item_cb) },
1385 { "RemoveToolbar", GTK_STOCK_DELETE, N_("_Delete Toolbar"), NULL,
1386 N_("Remove the selected toolbar"), G_CALLBACK (remove_toolbar_cb) },
1389 etoolbar->priv->manager = g_object_ref (manager);
1391 etoolbar->priv->actions = gtk_action_group_new ("ToolbarActions");
1392 gtk_action_group_set_translation_domain (etoolbar->priv->actions, GETTEXT_PACKAGE);
1393 gtk_action_group_add_actions (etoolbar->priv->actions, actions,
1394 G_N_ELEMENTS (actions), etoolbar);
1395 gtk_ui_manager_insert_action_group (manager, etoolbar->priv->actions, -1);
1396 g_object_unref (etoolbar->priv->actions);
1398 toolbar_visibility_refresh (etoolbar);
1401 GtkWidget * egg_editable_toolbar_get_selected (EggEditableToolbar *etoolbar)
1403 return etoolbar->priv->selected;
1407 egg_editable_toolbar_set_selected (EggEditableToolbar *etoolbar,
1410 GtkWidget *toolbar, *toolitem;
1413 etoolbar->priv->selected = widget;
1415 toolbar = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOLBAR) : NULL;
1416 toolitem = (widget != NULL) ? gtk_widget_get_ancestor (widget, GTK_TYPE_TOOL_ITEM) : NULL;
1420 gint tpos = get_toolbar_position (etoolbar, toolbar);
1421 editable = ((egg_toolbars_model_get_flags (etoolbar->priv->model, tpos) & EGG_TB_MODEL_NOT_EDITABLE) == 0);
1428 gtk_action_set_visible (find_action (etoolbar, "RemoveToolbar"), (toolbar != NULL) && (etoolbar->priv->edit_mode > 0));
1429 gtk_action_set_visible (find_action (etoolbar, "RemoveToolItem"), (toolitem != NULL) && editable);
1430 gtk_action_set_visible (find_action (etoolbar, "MoveToolItem"), (toolitem != NULL) && editable);
1434 set_edit_mode (EggEditableToolbar *etoolbar,
1437 EggEditableToolbarPrivate *priv = etoolbar->priv;
1440 i = priv->edit_mode;
1447 g_return_if_fail (priv->edit_mode > 0);
1450 i *= priv->edit_mode;
1454 for (i = get_n_toolbars (etoolbar)-1; i >= 0; i--)
1458 toolbar = get_toolbar_nth (etoolbar, i);
1459 n_items = gtk_toolbar_get_n_items (GTK_TOOLBAR (toolbar));
1461 if (n_items == 0 && priv->edit_mode == 0)
1463 egg_toolbars_model_remove_toolbar (priv->model, i);
1467 for (l = 0; l < n_items; l++)
1471 item = gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), l);
1473 configure_item_cursor (item, etoolbar);
1474 configure_item_sensitivity (item, etoolbar);
1482 egg_editable_toolbar_set_property (GObject *object,
1484 const GValue *value,
1487 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1491 case PROP_UI_MANAGER:
1492 egg_editable_toolbar_set_ui_manager (etoolbar, g_value_get_object (value));
1494 case PROP_TOOLBARS_MODEL:
1495 egg_editable_toolbar_set_model (etoolbar, g_value_get_object (value));
1498 egg_editable_toolbar_set_selected (etoolbar, g_value_get_object (value));
1500 case PROP_POPUP_PATH:
1501 etoolbar->priv->popup_path = g_strdup (g_value_get_string (value));
1503 case PROP_EDIT_MODE:
1504 set_edit_mode (etoolbar, g_value_get_boolean (value));
1507 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1513 egg_editable_toolbar_get_property (GObject *object,
1518 EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);
1522 case PROP_UI_MANAGER:
1523 g_value_set_object (value, etoolbar->priv->manager);
1525 case PROP_TOOLBARS_MODEL:
1526 g_value_set_object (value, etoolbar->priv->model);
1529 g_value_set_object (value, etoolbar->priv->selected);
1531 case PROP_EDIT_MODE:
1532 g_value_set_boolean (value, etoolbar->priv->edit_mode>0);
1535 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1541 egg_editable_toolbar_class_init (EggEditableToolbarClass *klass)
1543 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1545 object_class->dispose = egg_editable_toolbar_dispose;
1546 object_class->set_property = egg_editable_toolbar_set_property;
1547 object_class->get_property = egg_editable_toolbar_get_property;
1549 egg_editable_toolbar_signals[ACTION_REQUEST] =
1550 g_signal_new ("action_request",
1551 G_OBJECT_CLASS_TYPE (object_class),
1553 G_STRUCT_OFFSET (EggEditableToolbarClass, action_request),
1554 NULL, NULL, g_cclosure_marshal_VOID__STRING,
1555 G_TYPE_NONE, 1, G_TYPE_STRING);
1557 g_object_class_install_property (object_class,
1559 g_param_spec_object ("ui-manager",
1562 GTK_TYPE_UI_MANAGER,
1563 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1564 g_object_class_install_property (object_class,
1565 PROP_TOOLBARS_MODEL,
1566 g_param_spec_object ("model",
1569 EGG_TYPE_TOOLBARS_MODEL,
1570 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1571 g_object_class_install_property (object_class,
1573 g_param_spec_object ("selected",
1575 "Selected toolitem",
1577 G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1579 g_object_class_install_property (object_class,
1581 g_param_spec_string ("popup-path",
1585 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_boolean ("edit-mode",
1593 G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
1595 g_type_class_add_private (object_class, sizeof (EggEditableToolbarPrivate));
1599 egg_editable_toolbar_new (GtkUIManager *manager,
1600 const char *popup_path)
1602 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1603 "ui-manager", manager,
1604 "popup-path", popup_path,
1609 egg_editable_toolbar_new_with_model (GtkUIManager *manager,
1610 EggToolbarsModel *model,
1611 const char *popup_path)
1613 return GTK_WIDGET (g_object_new (EGG_TYPE_EDITABLE_TOOLBAR,
1614 "ui-manager", manager,
1616 "popup-path", popup_path,
1621 egg_editable_toolbar_get_edit_mode (EggEditableToolbar *etoolbar)
1623 EggEditableToolbarPrivate *priv = etoolbar->priv;
1625 return priv->edit_mode > 0;
1629 egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar,
1632 set_edit_mode (etoolbar, mode);
1633 g_object_notify (G_OBJECT (etoolbar), "edit-mode");
1637 egg_editable_toolbar_add_visibility (EggEditableToolbar *etoolbar,
1640 etoolbar->priv->visibility_paths = g_list_prepend
1641 (etoolbar->priv->visibility_paths, g_strdup (path));
1645 egg_editable_toolbar_show (EggEditableToolbar *etoolbar,
1648 EggEditableToolbarPrivate *priv = etoolbar->priv;
1649 EggToolbarsModel *model = priv->model;
1652 n_toolbars = egg_toolbars_model_n_toolbars (model);
1653 for (i = 0; i < n_toolbars; i++)
1655 const char *toolbar_name;
1657 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1658 if (strcmp (toolbar_name, name) == 0)
1660 gtk_widget_show (get_dock_nth (etoolbar, i));
1666 egg_editable_toolbar_hide (EggEditableToolbar *etoolbar,
1669 EggEditableToolbarPrivate *priv = etoolbar->priv;
1670 EggToolbarsModel *model = priv->model;
1673 n_toolbars = egg_toolbars_model_n_toolbars (model);
1674 for (i = 0; i < n_toolbars; i++)
1676 const char *toolbar_name;
1678 toolbar_name = egg_toolbars_model_toolbar_nth (model, i);
1679 if (strcmp (toolbar_name, name) == 0)
1681 gtk_widget_hide (get_dock_nth (etoolbar, i));
1687 egg_editable_toolbar_set_fixed (EggEditableToolbar *etoolbar,
1688 GtkToolbar *toolbar)
1690 EggEditableToolbarPrivate *priv = etoolbar->priv;
1692 g_return_if_fail (!toolbar || GTK_IS_TOOLBAR (toolbar));
1694 if (priv->fixed_toolbar)
1696 unparent_fixed (etoolbar);
1697 g_object_unref (priv->fixed_toolbar);
1698 priv->fixed_toolbar = NULL;
1703 priv->fixed_toolbar = GTK_WIDGET (toolbar);
1704 gtk_toolbar_set_show_arrow (toolbar, FALSE);
1705 g_object_ref_sink (toolbar);
1708 update_fixed (etoolbar);
1711 #define DEFAULT_ICON_HEIGHT 20
1712 #define DEFAULT_ICON_WIDTH 0
1715 fake_expose_widget (GtkWidget *widget,
1718 GdkWindow *tmp_window;
1719 GdkEventExpose event;
1721 event.type = GDK_EXPOSE;
1722 event.window = pixmap;
1723 event.send_event = FALSE;
1724 event.area = widget->allocation;
1725 event.region = NULL;
1728 tmp_window = widget->window;
1729 widget->window = pixmap;
1730 gtk_widget_send_expose (widget, (GdkEvent *) &event);
1731 widget->window = tmp_window;
1734 /* We should probably experiment some more with this.
1735 * Right now the rendered icon is pretty good for most
1736 * themes. However, the icon is slightly large for themes
1737 * with large toolbar icons.
1740 new_pixbuf_from_widget (GtkWidget *widget)
1744 GtkRequisition requisition;
1745 GtkAllocation allocation;
1752 icon_width = DEFAULT_ICON_WIDTH;
1754 screen = gtk_widget_get_screen (widget);
1756 if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen),
1757 GTK_ICON_SIZE_LARGE_TOOLBAR,
1761 icon_height = DEFAULT_ICON_HEIGHT;
1764 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1766 gtk_container_add (GTK_CONTAINER (window), widget);
1767 gtk_widget_realize (window);
1768 gtk_widget_show (widget);
1769 gtk_widget_realize (widget);
1770 gtk_widget_map (widget);
1772 /* Gtk will never set the width or height of a window to 0. So setting the width to
1773 * 0 and than getting it will provide us with the minimum width needed to render
1774 * the icon correctly, without any additional window background noise.
1775 * This is needed mostly for pixmap based themes.
1777 gtk_window_set_default_size (GTK_WINDOW (window), icon_width, icon_height);
1778 gtk_window_get_size (GTK_WINDOW (window),&icon_width, &icon_height);
1780 gtk_widget_size_request (window, &requisition);
1783 allocation.width = icon_width;
1784 allocation.height = icon_height;
1785 gtk_widget_size_allocate (window, &allocation);
1786 gtk_widget_size_request (window, &requisition);
1788 /* Create a pixmap */
1789 visual = gtk_widget_get_visual (window);
1790 pixmap = gdk_pixmap_new (NULL, icon_width, icon_height, visual->depth);
1791 gdk_drawable_set_colormap (GDK_DRAWABLE (pixmap), gtk_widget_get_colormap (window));
1793 /* Draw the window */
1794 gtk_widget_ensure_style (window);
1795 g_assert (window->style);
1796 g_assert (window->style->font_desc);
1798 fake_expose_widget (window, pixmap);
1799 fake_expose_widget (widget, pixmap);
1801 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, icon_width, icon_height);
1802 gdk_pixbuf_get_from_drawable (pixbuf, pixmap, NULL, 0, 0, 0, 0, icon_width, icon_height);
1804 gtk_widget_destroy (window);
1810 new_separator_pixbuf (void)
1812 GtkWidget *separator;
1815 separator = gtk_vseparator_new ();
1816 pixbuf = new_pixbuf_from_widget (separator);
1821 update_separator_image (GtkImage *image)
1823 GdkPixbuf *pixbuf = new_separator_pixbuf ();
1824 gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf);
1825 g_object_unref (pixbuf);
1829 style_set_cb (GtkWidget *widget,
1830 GtkStyle *previous_style,
1834 update_separator_image (image);
1839 _egg_editable_toolbar_new_separator_image (void)
1841 GtkWidget *image = gtk_image_new ();
1842 update_separator_image (GTK_IMAGE (image));
1843 g_signal_connect (G_OBJECT (image), "style_set",
1844 G_CALLBACK (style_set_cb), GTK_IMAGE (image));
1850 egg_editable_toolbar_get_model (EggEditableToolbar *etoolbar)
1852 return etoolbar->priv->model;