X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=cut-n-paste%2Ftoolbar-editor%2Fegg-toolbar-editor.c;h=5e75ba82aa4078c7ddbd0f4ad5a8bec247e5237b;hb=223cc03e0275c77c4482ed0495b3bd15993a3ab8;hp=fdf6e3f0fc86c1cfffa88e66cf8074aecdb517e6;hpb=88f0701b10f70b8aede0f7e23014875ab72c2e26;p=evince.git diff --git a/cut-n-paste/toolbar-editor/egg-toolbar-editor.c b/cut-n-paste/toolbar-editor/egg-toolbar-editor.c index fdf6e3f0..5e75ba82 100644 --- a/cut-n-paste/toolbar-editor/egg-toolbar-editor.c +++ b/cut-n-paste/toolbar-editor/egg-toolbar-editor.c @@ -13,7 +13,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * $Id$ */ @@ -25,14 +25,6 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include @@ -44,8 +36,7 @@ static const GtkTargetEntry source_drag_types[] = { {EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0}, }; -static void egg_toolbar_editor_class_init (EggToolbarEditorClass *klass); -static void egg_toolbar_editor_init (EggToolbarEditor *t); + static void egg_toolbar_editor_finalize (GObject *object); static void update_editor_sheet (EggToolbarEditor *editor); @@ -56,7 +47,13 @@ enum PROP_TOOLBARS_MODEL }; -static GObjectClass *parent_class = NULL; +enum +{ + SIGNAL_HANDLER_ITEM_ADDED, + SIGNAL_HANDLER_ITEM_REMOVED, + SIGNAL_HANDLER_TOOLBAR_REMOVED, + SIGNAL_HANDLER_LIST_SIZE /* Array size */ +}; #define EGG_TOOLBAR_EDITOR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EGG_TYPE_TOOLBAR_EDITOR, EggToolbarEditorPrivate)) @@ -69,34 +66,12 @@ struct EggToolbarEditorPrivate GtkWidget *scrolled_window; GList *actions_list; GList *factory_list; -}; - -GType -egg_toolbar_editor_get_type (void) -{ - static GType type = 0; - if (G_UNLIKELY (type == 0)) - { - static const GTypeInfo our_info = { - sizeof (EggToolbarEditorClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) egg_toolbar_editor_class_init, - NULL, - NULL, /* class_data */ - sizeof (EggToolbarEditor), - 0, /* n_preallocs */ - (GInstanceInitFunc) egg_toolbar_editor_init - }; - - type = g_type_register_static (GTK_TYPE_VBOX, - "EggToolbarEditor", - &our_info, 0); - } + /* These handlers need to be sanely disconnected when switching models */ + gulong sig_handlers[SIGNAL_HANDLER_LIST_SIZE]; +}; - return type; -} +G_DEFINE_TYPE (EggToolbarEditor, egg_toolbar_editor, GTK_TYPE_VBOX); static gint compare_items (gconstpointer a, @@ -109,7 +84,7 @@ compare_items (gconstpointer a, "egg-collate-key"); char *key2 = g_object_get_data (G_OBJECT (item2), "egg-collate-key"); - + return strcmp (key1, key2); } @@ -164,21 +139,61 @@ toolbar_removed_cb (EggToolbarsModel *model, } static void +egg_toolbar_editor_disconnect_model (EggToolbarEditor *t) +{ + EggToolbarEditorPrivate *priv = t->priv; + EggToolbarsModel *model = priv->model; + gulong handler; + int i; + + for (i = 0; i < SIGNAL_HANDLER_LIST_SIZE; i++) + { + handler = priv->sig_handlers[i]; + + if (handler != 0) + { + if (g_signal_handler_is_connected (model, handler)) + { + g_signal_handler_disconnect (model, handler); + } + + priv->sig_handlers[i] = 0; + } + } +} + +void egg_toolbar_editor_set_model (EggToolbarEditor *t, EggToolbarsModel *model) { + EggToolbarEditorPrivate *priv; + g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (t)); + g_return_if_fail (model != NULL); + + priv = t->priv; + + if (priv->model) + { + if (G_UNLIKELY (priv->model == model)) return; + + egg_toolbar_editor_disconnect_model (t); + g_object_unref (priv->model); + } + + priv->model = g_object_ref (model); - t->priv->model = g_object_ref (model); - update_editor_sheet (t); - g_signal_connect_object (model, "item_added", - G_CALLBACK (item_added_or_removed_cb), t, 0); - g_signal_connect_object (model, "item_removed", - G_CALLBACK (item_added_or_removed_cb), t, 0); - g_signal_connect_object (model, "toolbar_removed", - G_CALLBACK (toolbar_removed_cb), t, 0); + priv->sig_handlers[SIGNAL_HANDLER_ITEM_ADDED] = + g_signal_connect_object (model, "item_added", + G_CALLBACK (item_added_or_removed_cb), t, 0); + priv->sig_handlers[SIGNAL_HANDLER_ITEM_REMOVED] = + g_signal_connect_object (model, "item_removed", + G_CALLBACK (item_added_or_removed_cb), t, 0); + priv->sig_handlers[SIGNAL_HANDLER_TOOLBAR_REMOVED] = + g_signal_connect_object (model, "toolbar_removed", + G_CALLBACK (toolbar_removed_cb), t, 0); } static void @@ -224,8 +239,6 @@ egg_toolbar_editor_class_init (EggToolbarEditorClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - parent_class = g_type_class_peek_parent (klass); - object_class->finalize = egg_toolbar_editor_finalize; object_class->set_property = egg_toolbar_editor_set_property; object_class->get_property = egg_toolbar_editor_get_property; @@ -245,7 +258,7 @@ egg_toolbar_editor_class_init (EggToolbarEditorClass *klass) "Toolbars Model", EGG_TYPE_TOOLBARS_MODEL, G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | - G_PARAM_CONSTRUCT_ONLY)); + G_PARAM_CONSTRUCT)); g_type_class_add_private (object_class, sizeof (EggToolbarEditorPrivate)); } @@ -262,13 +275,14 @@ egg_toolbar_editor_finalize (GObject *object) if (editor->priv->model) { + egg_toolbar_editor_disconnect_model (editor); g_object_unref (editor->priv->model); } g_list_free (editor->priv->actions_list); g_list_free (editor->priv->factory_list); - G_OBJECT_CLASS (parent_class)->finalize (object); + G_OBJECT_CLASS (egg_toolbar_editor_parent_class)->finalize (object); } GtkWidget * @@ -307,8 +321,9 @@ drag_data_get_cb (GtkWidget *widget, target = g_object_get_data (G_OBJECT (widget), "egg-item-name"); g_return_if_fail (target != NULL); - - gtk_selection_data_set (selection_data, selection_data->target, 8, + + gtk_selection_data_set (selection_data, + gtk_selection_data_get_target (selection_data), 8, (const guchar *) target, strlen (target)); } @@ -342,11 +357,13 @@ static void set_drag_cursor (GtkWidget *widget) { GdkCursor *cursor; - - /* FIXME multihead */ - cursor = gdk_cursor_new (GDK_HAND2); + GdkScreen *screen; + + screen = gtk_widget_get_screen (widget); - gdk_window_set_cursor (widget->window, cursor); + cursor = gdk_cursor_new_for_display (gdk_screen_get_display (screen), + GDK_HAND2); + gdk_window_set_cursor (gtk_widget_get_window (widget), cursor); gdk_cursor_unref (cursor); } @@ -460,16 +477,16 @@ editor_create_item_from_name (EggToolbarEditor *editor, const char *item_name; char *short_label; const char *collate_key; - + if (strcmp (name, "_separator") == 0) { GtkWidget *icon; - + icon = _egg_editable_toolbar_new_separator_image (); short_label = _("Separator"); item_name = g_strdup (name); collate_key = g_utf8_collate_key (short_label, -1); - item = editor_create_item (editor, GTK_IMAGE (icon), + item = editor_create_item (editor, GTK_IMAGE (icon), short_label, drag_action); } else @@ -477,7 +494,7 @@ editor_create_item_from_name (EggToolbarEditor *editor, GtkAction *action; GtkWidget *icon; char *stock_id, *icon_name = NULL; - + action = find_action (editor, name); g_return_val_if_fail (action != NULL, NULL); @@ -504,12 +521,12 @@ editor_create_item_from_name (EggToolbarEditor *editor, g_free (stock_id); g_free (icon_name); } - + g_object_set_data_full (G_OBJECT (item), "egg-collate-key", (gpointer) collate_key, g_free); g_object_set_data_full (G_OBJECT (item), "egg-item-name", (gpointer) item_name, g_free); - + return item; } @@ -521,10 +538,10 @@ append_table (GtkTable *table, GList *items, gint y, gint width) gint x = 0, height; GtkWidget *alignment; GtkWidget *item; - + height = g_list_length (items) / width + 1; gtk_table_resize (table, height, width); - + if (y > 0) { item = gtk_hseparator_new (); @@ -532,10 +549,10 @@ append_table (GtkTable *table, GList *items, gint y, gint width) gtk_container_add (GTK_CONTAINER (alignment), item); gtk_widget_show (alignment); gtk_widget_show (item); - + gtk_table_attach_defaults (table, alignment, 0, width, y-1, y+1); } - + for (; items != NULL; items = items->next) { item = items->data; @@ -543,7 +560,7 @@ append_table (GtkTable *table, GList *items, gint y, gint width) gtk_container_add (GTK_CONTAINER (alignment), item); gtk_widget_show (alignment); gtk_widget_show (item); - + if (x >= width) { x = 0; @@ -552,7 +569,7 @@ append_table (GtkTable *table, GList *items, gint y, gint width) gtk_table_attach_defaults (table, alignment, x, x+1, y, y+1); x++; } - + y++; } return y; @@ -568,7 +585,7 @@ update_editor_sheet (EggToolbarEditor *editor) GtkWidget *viewport; g_return_if_fail (EGG_IS_TOOLBAR_EDITOR (editor)); - + /* Create new table. */ table = gtk_table_new (0, 0, TRUE); editor->priv->table = table; @@ -578,7 +595,7 @@ update_editor_sheet (EggToolbarEditor *editor) gtk_drag_dest_set (table, GTK_DEST_DEFAULT_ALL, dest_drag_types, G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE | GDK_ACTION_COPY); - + /* Build two lists of items (one for copying, one for moving). */ items = egg_toolbars_model_get_name_avail (editor->priv->model); while (items->len > 0) @@ -586,10 +603,10 @@ update_editor_sheet (EggToolbarEditor *editor) GtkWidget *item; const char *name; gint flags; - + name = g_ptr_array_index (items, 0); g_ptr_array_remove_index_fast (items, 0); - + flags = egg_toolbars_model_get_name_flags (editor->priv->model, name); if ((flags & EGG_TB_MODEL_NAME_INFINITE) == 0) { @@ -609,19 +626,19 @@ update_editor_sheet (EggToolbarEditor *editor) y = 0; y = append_table (GTK_TABLE (table), to_move, y, 4); y = append_table (GTK_TABLE (table), to_copy, y, 4); - + g_list_free (to_move); g_list_free (to_copy); g_ptr_array_free (items, TRUE); - + /* Delete old table. */ - viewport = GTK_BIN (editor->priv->scrolled_window)->child; + viewport = gtk_bin_get_child (GTK_BIN (editor->priv->scrolled_window)); if (viewport) { gtk_container_remove (GTK_CONTAINER (viewport), - GTK_BIN (viewport)->child); + gtk_bin_get_child (GTK_BIN (viewport))); } - + /* Add table to window. */ gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (editor->priv->scrolled_window), table);