From 27ae6e03f698835c1683c03b7cfc0e401d0f601f Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Thu, 10 Jun 2004 19:05:53 +0000 Subject: Merging bookmarksbar-separation branch. 2004-06-10 Christian Persch Merging bookmarksbar-separation branch. --- lib/egg/egg-editable-toolbar.c | 186 +++++++++++++++++++++++++---------------- lib/egg/egg-editable-toolbar.h | 3 +- lib/egg/egg-toolbars-model.c | 70 ++++++++++++++-- lib/egg/egg-toolbars-model.h | 27 +++--- lib/egg/eggmarshalers.c | 82 +++++++++++++++++- lib/egg/eggmarshalers.h | 16 ++++ lib/egg/eggmarshalers.list | 2 + 7 files changed, 293 insertions(+), 93 deletions(-) (limited to 'lib/egg') diff --git a/lib/egg/egg-editable-toolbar.c b/lib/egg/egg-editable-toolbar.c index 572068877..649935b1b 100755 --- a/lib/egg/egg-editable-toolbar.c +++ b/lib/egg/egg-editable-toolbar.c @@ -177,7 +177,6 @@ find_action (EggEditableToolbar *t, l = gtk_ui_manager_get_action_groups (t->priv->merge); - g_return_val_if_fail (EGG_IS_EDITABLE_TOOLBAR (t), NULL); g_return_val_if_fail (name != NULL, NULL); for (; l != NULL; l = l->next) @@ -365,6 +364,8 @@ create_item_from_action (EggEditableToolbar *t, } else { + g_return_val_if_fail (action_name != NULL, NULL); + g_signal_emit (G_OBJECT (t), egg_editable_toolbar_signals[ACTION_REQUEST], 0, action_name); @@ -600,6 +601,24 @@ toolbar_drag_motion_cb (GtkWidget *widget, int index; GtkToolbar *toolbar = GTK_TOOLBAR (widget); GtkToolItem *item; + GtkWidget *source; + + source = gtk_drag_get_source_widget (context); + if (source) + { + EggTbModelFlags flags; + int pos; + + pos = get_toolbar_position (etoolbar, widget); + flags = egg_toolbars_model_get_flags (etoolbar->priv->model, pos); + + if ((flags & EGG_TB_MODEL_ACCEPT_ITEMS_ONLY) && + !GTK_IS_TOOL_ITEM (source)) + { + gdk_drag_status (context, 0, time); + return FALSE; + } + } target = gtk_drag_dest_find_target (widget, context, NULL); if (target == GDK_NONE) @@ -863,27 +882,6 @@ item_removed_cb (EggToolbarsModel *model, } } -static void -toolbars_clean (EggEditableToolbar *t) -{ - GList *children, *l; - - if (t->priv->fixed_toolbar) - { - unset_fixed_style (t); - unparent_fixed (t); - } - - children = gtk_container_get_children (GTK_CONTAINER (t)); - - for (l = children; l != NULL; l = l->next) - { - gtk_widget_destroy (GTK_WIDGET (l->data)); - } - - g_list_free (children); -} - static void egg_editable_toolbar_construct (EggEditableToolbar *t) { @@ -891,6 +889,7 @@ egg_editable_toolbar_construct (EggEditableToolbar *t) EggToolbarsModel *model = t->priv->model; g_return_if_fail (model != NULL); + g_return_if_fail (t->priv->merge != NULL); n_toolbars = egg_toolbars_model_n_toolbars (model); @@ -944,74 +943,108 @@ egg_editable_toolbar_construct (EggEditableToolbar *t) } } - update_fixed (t); + update_fixed (t); } static void -egg_editable_toolbar_set_model (EggEditableToolbar *t, - EggToolbarsModel *model) +egg_editable_toolbar_realize (GtkWidget *widget) { - g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model)); - g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (t)); + EggEditableToolbar *toolbar = EGG_EDITABLE_TOOLBAR (widget); + EggToolbarsModel *model = toolbar->priv->model; - if (t->priv->model == model) return; + GTK_WIDGET_CLASS (parent_class)->realize (widget); - if (t->priv->model) + g_return_if_fail (model != NULL); + + egg_editable_toolbar_construct (toolbar); + + g_signal_connect (model, "item_added", + G_CALLBACK (item_added_cb), toolbar); + g_signal_connect (model, "item_removed", + G_CALLBACK (item_removed_cb), toolbar); + g_signal_connect (model, "toolbar_added", + G_CALLBACK (toolbar_added_cb), toolbar); + g_signal_connect (model, "toolbar_removed", + G_CALLBACK (toolbar_removed_cb), toolbar); + g_signal_connect (model, "toolbar_changed", + G_CALLBACK (toolbar_changed_cb), toolbar); +} + +static void +egg_editable_toolbar_unrealize (GtkWidget *widget) +{ + EggEditableToolbar *toolbar = EGG_EDITABLE_TOOLBAR (widget); + EggToolbarsModel *model = toolbar->priv->model; + GList *children, *l; + + g_return_if_fail (model != NULL); + + g_signal_handlers_disconnect_by_func + (model, G_CALLBACK (item_added_cb), toolbar); + g_signal_handlers_disconnect_by_func + (model, G_CALLBACK (item_removed_cb), toolbar); + g_signal_handlers_disconnect_by_func + (model, G_CALLBACK (toolbar_added_cb), toolbar); + g_signal_handlers_disconnect_by_func + (model, G_CALLBACK (toolbar_removed_cb), toolbar); + g_signal_handlers_disconnect_by_func + (model, G_CALLBACK (toolbar_changed_cb), toolbar); + + if (toolbar->priv->fixed_toolbar) { - g_signal_handlers_disconnect_by_func - (t->priv->model, G_CALLBACK (item_added_cb), t); - g_signal_handlers_disconnect_by_func - (t->priv->model, G_CALLBACK (item_removed_cb), t); - g_signal_handlers_disconnect_by_func - (t->priv->model, G_CALLBACK (toolbar_added_cb), t); - g_signal_handlers_disconnect_by_func - (t->priv->model, G_CALLBACK (toolbar_removed_cb), t); - g_signal_handlers_disconnect_by_func - (t->priv->model, G_CALLBACK (toolbar_changed_cb), t); - - g_object_unref (t->priv->model); + unset_fixed_style (toolbar); + unparent_fixed (toolbar); } - t->priv->model = g_object_ref (model); + children = gtk_container_get_children (GTK_CONTAINER (toolbar)); - toolbars_clean (t); - if (t->priv->merge != NULL) + for (l = children; l != NULL; l = l->next) { - egg_editable_toolbar_construct (t); + gtk_widget_destroy (GTK_WIDGET (l->data)); } - g_signal_connect_object (model, "item_added", - G_CALLBACK (item_added_cb), t, 0); - g_signal_connect_object (model, "item_removed", - G_CALLBACK (item_removed_cb), t, 0); - g_signal_connect_object (model, "toolbar_added", - G_CALLBACK (toolbar_added_cb), t, 0); - g_signal_connect_object (model, "toolbar_removed", - G_CALLBACK (toolbar_removed_cb), t, 0); - g_signal_connect_object (model, "toolbar_changed", - G_CALLBACK (toolbar_changed_cb), t, 0); + g_list_free (children); + + GTK_WIDGET_CLASS (parent_class)->unrealize (widget); } static void -egg_editable_toolbar_set_merge (EggEditableToolbar *t, - GtkUIManager *merge) +egg_editable_toolbar_set_model (EggEditableToolbar *toolbar, + EggToolbarsModel *model) { - g_return_if_fail (GTK_IS_UI_MANAGER (merge)); - g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (t)); + GtkWidget *widget = GTK_WIDGET (toolbar); - if (t->priv->merge == merge) return; + g_return_if_fail (EGG_IS_TOOLBARS_MODEL (model)); + g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (toolbar)); - if (t->priv->merge) + if (toolbar->priv->model == model) return; + + if (GTK_WIDGET_VISIBLE (widget)) { - g_object_unref (t->priv->merge); + gtk_widget_hide (widget); } - t->priv->merge = g_object_ref (merge); + if(GTK_WIDGET_REALIZED (widget)) + { + gtk_widget_unrealize (widget); + } - if (t->priv->model != NULL) + if (toolbar->priv->model) { - egg_editable_toolbar_construct (t); + g_object_unref (toolbar->priv->model); } + + toolbar->priv->model = g_object_ref (model); +} + +static void +egg_editable_toolbar_set_merge (EggEditableToolbar *t, + GtkUIManager *merge) +{ + g_return_if_fail (GTK_IS_UI_MANAGER (merge)); + g_return_if_fail (EGG_IS_EDITABLE_TOOLBAR (t)); + + t->priv->merge = g_object_ref (merge); } static void @@ -1030,6 +1063,9 @@ egg_editable_toolbar_set_property (GObject *object, case PROP_TOOLBARS_MODEL: egg_editable_toolbar_set_model (t, g_value_get_object (value)); break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; } } @@ -1049,6 +1085,9 @@ egg_editable_toolbar_get_property (GObject *object, case PROP_TOOLBARS_MODEL: g_value_set_object (value, t->priv->model); break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; } } @@ -1056,6 +1095,7 @@ static void egg_editable_toolbar_class_init (EggEditableToolbarClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); parent_class = g_type_class_peek_parent (klass); @@ -1063,6 +1103,9 @@ egg_editable_toolbar_class_init (EggEditableToolbarClass *klass) object_class->set_property = egg_editable_toolbar_set_property; object_class->get_property = egg_editable_toolbar_get_property; + widget_class->realize = egg_editable_toolbar_realize; + widget_class->unrealize = egg_editable_toolbar_unrealize; + egg_editable_toolbar_signals[ACTION_REQUEST] = g_signal_new ("action_request", G_OBJECT_CLASS_TYPE (object_class), @@ -1093,10 +1136,6 @@ static void egg_editable_toolbar_init (EggEditableToolbar *t) { t->priv = EGG_EDITABLE_TOOLBAR_GET_PRIVATE (t); - - t->priv->merge = NULL; - t->priv->edit_mode = FALSE; - t->priv->dragged_item = NULL; } static void @@ -1158,7 +1197,7 @@ egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar, GtkToolItem *item; const char *action_name, *type; gboolean is_separator; - GtkAction *action; + GtkAction *action = NULL; egg_toolbars_model_item_nth (etoolbar->priv->model, i, l, &is_separator, &action_name, &type); @@ -1416,3 +1455,10 @@ _egg_editable_toolbar_new_separator_image (void) return image; } + +EggToolbarsModel * +egg_editable_toolbar_get_model (EggEditableToolbar *etoolbar) +{ + return etoolbar->priv->model; +} + diff --git a/lib/egg/egg-editable-toolbar.h b/lib/egg/egg-editable-toolbar.h index c946472bd..0e5b72cd9 100755 --- a/lib/egg/egg-editable-toolbar.h +++ b/lib/egg/egg-editable-toolbar.h @@ -54,12 +54,13 @@ struct EggEditableToolbarClass GtkVBoxClass parent_class; void (* action_request) (EggEditableToolbar *etoolbar, - char *action_name); + const char *action_name); }; GType egg_editable_toolbar_get_type (void); GtkWidget *egg_editable_toolbar_new (GtkUIManager *merge, EggToolbarsModel *model); +EggToolbarsModel *egg_editable_toolbar_get_model (EggEditableToolbar *etoolbar); void egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar, gboolean mode); gboolean egg_editable_toolbar_get_edit_mode (EggEditableToolbar *etoolbar); diff --git a/lib/egg/egg-toolbars-model.c b/lib/egg/egg-toolbars-model.c index 3949e54d9..c4ed3217e 100755 --- a/lib/egg/egg-toolbars-model.c +++ b/lib/egg/egg-toolbars-model.c @@ -35,6 +35,9 @@ enum TOOLBAR_ADDED, TOOLBAR_CHANGED, TOOLBAR_REMOVED, + GET_ITEM_TYPE, + GET_ITEM_ID, + GET_ITEM_DATA, LAST_SIGNAL }; @@ -442,6 +445,8 @@ egg_toolbars_model_load (EggToolbarsModel *t, g_return_val_if_fail (EGG_IS_TOOLBARS_MODEL (t), FALSE); + if (!xml_file || !g_file_test (xml_file, G_FILE_TEST_EXISTS)) return FALSE; + doc = xmlParseFile (xml_file); if (doc == NULL) { @@ -450,7 +455,6 @@ egg_toolbars_model_load (EggToolbarsModel *t, } root = xmlDocGetRootElement (doc); - t->priv->toolbars = g_node_new (NULL); parse_toolbars (t, root->children); xmlFreeDoc (doc); @@ -496,6 +500,23 @@ impl_get_item_type (EggToolbarsModel *t, return NULL; } +static gboolean +_egg_accumulator_STRING (GSignalInvocationHint *ihint, + GValue *return_accu, + const GValue *handler_return, + gpointer dummy) +{ + gboolean continue_emission; + const char *retval; + + retval = g_value_get_string (handler_return); + g_value_set_string (return_accu, retval); + continue_emission = !retval || !retval[0]; + + return continue_emission; +} + + static void egg_toolbars_model_class_init (EggToolbarsModelClass *klass) { @@ -545,6 +566,30 @@ egg_toolbars_model_class_init (EggToolbarsModelClass *klass) G_STRUCT_OFFSET (EggToolbarsModelClass, toolbar_changed), NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT); + egg_toolbars_model_signals[GET_ITEM_TYPE] = + g_signal_new ("get_item_type", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EggToolbarsModelClass, get_item_type), + _egg_accumulator_STRING, NULL, + _egg_marshal_STRING__POINTER, + G_TYPE_STRING, 1, G_TYPE_POINTER); + egg_toolbars_model_signals[GET_ITEM_ID] = + g_signal_new ("get_item_id", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EggToolbarsModelClass, get_item_id), + _egg_accumulator_STRING, NULL, + _egg_marshal_STRING__STRING_STRING, + G_TYPE_STRING, 2, G_TYPE_STRING, G_TYPE_STRING); + egg_toolbars_model_signals[GET_ITEM_DATA] = + g_signal_new ("get_item_data", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EggToolbarsModelClass, get_item_data), + _egg_accumulator_STRING, NULL, + _egg_marshal_STRING__STRING_STRING, + G_TYPE_STRING, 2, G_TYPE_STRING, G_TYPE_STRING); g_type_class_add_private (object_class, sizeof (EggToolbarsModelPrivate)); } @@ -554,7 +599,7 @@ egg_toolbars_model_init (EggToolbarsModel *t) { t->priv =EGG_TOOLBARS_MODEL_GET_PRIVATE (t); - t->priv->toolbars = NULL; + t->priv->toolbars = g_node_new (NULL); } static void @@ -702,8 +747,11 @@ egg_toolbars_model_get_item_id (EggToolbarsModel *t, const char *type, const char *name) { - EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (t); - return klass->get_item_id (t, type, name); + char *retval; + + g_signal_emit (t, egg_toolbars_model_signals[GET_ITEM_ID], 0, type, name, &retval); + + return retval; } char * @@ -711,14 +759,20 @@ egg_toolbars_model_get_item_data (EggToolbarsModel *t, const char *type, const char *id) { - EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (t); - return klass->get_item_data (t, type, id); + char *retval; + + g_signal_emit (t, egg_toolbars_model_signals[GET_ITEM_DATA], 0, type, id, &retval); + + return retval; } char * egg_toolbars_model_get_item_type (EggToolbarsModel *t, GdkAtom type) { - EggToolbarsModelClass *klass = EGG_TOOLBARS_MODEL_GET_CLASS (t); - return klass->get_item_type (t, type); + char *retval; + + g_signal_emit (t, egg_toolbars_model_signals[GET_ITEM_TYPE], 0, type, &retval); + + return retval; } diff --git a/lib/egg/egg-toolbars-model.h b/lib/egg/egg-toolbars-model.h index f9ca2105c..565b9ae01 100755 --- a/lib/egg/egg-toolbars-model.h +++ b/lib/egg/egg-toolbars-model.h @@ -41,11 +41,12 @@ typedef struct EggToolbarsModelPrivate EggToolbarsModelPrivate; typedef enum { - EGG_TB_MODEL_NOT_REMOVABLE = 1 << 0, - EGG_TB_MODEL_ICONS_ONLY = 1 << 1, - EGG_TB_MODEL_TEXT_ONLY = 1 << 2, - EGG_TB_MODEL_ICONS_TEXT = 1 << 3, - EGG_TB_MODEL_ICONS_TEXT_HORIZ = 1 << 4, + EGG_TB_MODEL_NOT_REMOVABLE = 1 << 0, + EGG_TB_MODEL_ICONS_ONLY = 1 << 1, + EGG_TB_MODEL_TEXT_ONLY = 1 << 2, + EGG_TB_MODEL_ICONS_TEXT = 1 << 3, + EGG_TB_MODEL_ICONS_TEXT_HORIZ = 1 << 4, + EGG_TB_MODEL_ACCEPT_ITEMS_ONLY = 1 << 5 } EggTbModelFlags; struct EggToolbarsModel @@ -73,6 +74,14 @@ struct EggToolbarsModelClass int position); void (* toolbar_removed) (EggToolbarsModel *group, int position); + char * (* get_item_type) (EggToolbarsModel *model, + GdkAtom dnd_type); + char * (* get_item_id) (EggToolbarsModel *model, + const char *type, + const char *data); + char * (* get_item_data) (EggToolbarsModel *model, + const char *type, + const char *id); /* Virtual Table */ gboolean (* add_item) (EggToolbarsModel *t, @@ -80,14 +89,6 @@ struct EggToolbarsModelClass int position, const char *id, const char *type); - char * (* get_item_type) (EggToolbarsModel *t, - GdkAtom dnd_type); - char * (* get_item_id) (EggToolbarsModel *t, - const char *type, - const char *data); - char * (* get_item_data) (EggToolbarsModel *t, - const char *type, - const char *id); }; GType egg_toolbars_model_get_type (void); diff --git a/lib/egg/eggmarshalers.c b/lib/egg/eggmarshalers.c index f2749951d..1d336db0e 100644 --- a/lib/egg/eggmarshalers.c +++ b/lib/egg/eggmarshalers.c @@ -1,4 +1,4 @@ -#include "eggmarshalers.h" + #include @@ -556,3 +556,83 @@ _egg_marshal_BOOLEAN__OBJECT_STRING_STRING (GClosure *closure, g_value_set_boolean (return_value, v_return); } +/* STRING:POINTER (eggmarshalers.list:18) */ +void +_egg_marshal_STRING__POINTER (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) +{ + typedef gchar* (*GMarshalFunc_STRING__POINTER) (gpointer data1, + gpointer arg_1, + gpointer data2); + register GMarshalFunc_STRING__POINTER callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + gchar* v_return; + + g_return_if_fail (return_value != NULL); + g_return_if_fail (n_param_values == 2); + + if (G_CCLOSURE_SWAP_DATA (closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer (param_values + 0); + } + else + { + data1 = g_value_peek_pointer (param_values + 0); + data2 = closure->data; + } + callback = (GMarshalFunc_STRING__POINTER) (marshal_data ? marshal_data : cc->callback); + + v_return = callback (data1, + g_marshal_value_peek_pointer (param_values + 1), + data2); + + g_value_take_string (return_value, v_return); +} + +/* STRING:STRING,STRING (eggmarshalers.list:19) */ +void +_egg_marshal_STRING__STRING_STRING (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data) +{ + typedef gchar* (*GMarshalFunc_STRING__STRING_STRING) (gpointer data1, + gpointer arg_1, + gpointer arg_2, + gpointer data2); + register GMarshalFunc_STRING__STRING_STRING callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + gchar* v_return; + + g_return_if_fail (return_value != NULL); + g_return_if_fail (n_param_values == 3); + + if (G_CCLOSURE_SWAP_DATA (closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer (param_values + 0); + } + else + { + data1 = g_value_peek_pointer (param_values + 0); + data2 = closure->data; + } + callback = (GMarshalFunc_STRING__STRING_STRING) (marshal_data ? marshal_data : cc->callback); + + v_return = callback (data1, + g_marshal_value_peek_string (param_values + 1), + g_marshal_value_peek_string (param_values + 2), + data2); + + g_value_take_string (return_value, v_return); +} + diff --git a/lib/egg/eggmarshalers.h b/lib/egg/eggmarshalers.h index c375dbc04..af720ee2b 100644 --- a/lib/egg/eggmarshalers.h +++ b/lib/egg/eggmarshalers.h @@ -121,6 +121,22 @@ extern void _egg_marshal_BOOLEAN__OBJECT_STRING_STRING (GClosure *closure, gpointer invocation_hint, gpointer marshal_data); +/* STRING:POINTER (eggmarshalers.list:18) */ +extern void _egg_marshal_STRING__POINTER (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + +/* STRING:STRING,STRING (eggmarshalers.list:19) */ +extern void _egg_marshal_STRING__STRING_STRING (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + G_END_DECLS #endif /* ___egg_marshal_MARSHAL_H__ */ diff --git a/lib/egg/eggmarshalers.list b/lib/egg/eggmarshalers.list index d443ca7cd..7b79b0f3a 100644 --- a/lib/egg/eggmarshalers.list +++ b/lib/egg/eggmarshalers.list @@ -15,3 +15,5 @@ VOID:OBJECT,ENUM,BOXED VOID:BOXED BOOLEAN:BOOLEAN BOOLEAN:OBJECT,STRING,STRING +STRING:POINTER +STRING:STRING,STRING -- cgit v1.2.3