diff options
author | Marco Pesenti Gritti <marco@it.gnome.org> | 2003-05-11 20:24:35 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <mpeseng@src.gnome.org> | 2003-05-11 20:24:35 +0800 |
commit | 1ffbaefc6b9d99f76fb666215709b6ab4e83d547 (patch) | |
tree | bf6cbc16d0f0a87c19ebcbe507f490c222a90d90 /lib/egg | |
parent | 3ab85f2df9c5f3201d984d7e6fbe65767f340143 (diff) | |
download | gsoc2013-epiphany-1ffbaefc6b9d99f76fb666215709b6ab4e83d547.tar gsoc2013-epiphany-1ffbaefc6b9d99f76fb666215709b6ab4e83d547.tar.gz gsoc2013-epiphany-1ffbaefc6b9d99f76fb666215709b6ab4e83d547.tar.bz2 gsoc2013-epiphany-1ffbaefc6b9d99f76fb666215709b6ab4e83d547.tar.lz gsoc2013-epiphany-1ffbaefc6b9d99f76fb666215709b6ab4e83d547.tar.xz gsoc2013-epiphany-1ffbaefc6b9d99f76fb666215709b6ab4e83d547.tar.zst gsoc2013-epiphany-1ffbaefc6b9d99f76fb666215709b6ab4e83d547.zip |
Update
2003-05-11 Marco Pesenti Gritti <marco@it.gnome.org>
* lib/egg/egg-action.c:
* lib/egg/eggseparatortoolitem.c:
* lib/egg/eggtoggletoolbutton.c:
* lib/egg/eggtoolbar.c:
* lib/egg/eggtoolbutton.c:
* lib/egg/eggtoolitem.c:
* lib/egg/eggtoolitem.h:
Update
* src/bookmarks/Makefile.am:
* src/bookmarks/ephy-bookmarks.c:
* src/bookmarks/ephy-bookmarks-export.c:
* src/bookmarks/ephy-bookmarks-export.h:
Export bookmarks in an rdf format (RSS was perfect,
so I just used it instead of inventing a new one).
This is useful to ensure compatibility in case
of database formats changes. It will be used also
as import format for ephy. Also I think it can be easily
displayed, need to talk with Edd about the css url though.
Thanks to Edd Dumbill for the help with this.
Diffstat (limited to 'lib/egg')
-rw-r--r-- | lib/egg/egg-action.c | 12 | ||||
-rw-r--r-- | lib/egg/eggseparatortoolitem.c | 9 | ||||
-rw-r--r-- | lib/egg/eggtoggletoolbutton.c | 38 | ||||
-rw-r--r-- | lib/egg/eggtoolbar.c | 39 | ||||
-rw-r--r-- | lib/egg/eggtoolbutton.c | 25 | ||||
-rw-r--r-- | lib/egg/eggtoolitem.c | 102 | ||||
-rw-r--r-- | lib/egg/eggtoolitem.h | 58 |
7 files changed, 188 insertions, 95 deletions
diff --git a/lib/egg/egg-action.c b/lib/egg/egg-action.c index 8cb099048..d7f24ebee 100644 --- a/lib/egg/egg-action.c +++ b/lib/egg/egg-action.c @@ -408,10 +408,18 @@ egg_action_sync_stock_id (EggAction *action, GParamSpec *pspec, } } -static GtkWidget * +static gboolean egg_action_create_menu_proxy (EggToolItem *tool_item, EggAction *action) { - return egg_action_create_menu_item (action); + GtkWidget *menu_item = egg_action_create_menu_item (action); + + g_object_ref (menu_item); + gtk_object_sink (GTK_OBJECT (menu_item)); + + egg_tool_item_set_proxy_menu_item (tool_item, "egg-action-menu-item", menu_item); + g_object_unref (menu_item); + + return TRUE; } static void diff --git a/lib/egg/eggseparatortoolitem.c b/lib/egg/eggseparatortoolitem.c index e3fe098fc..0f4f9871f 100644 --- a/lib/egg/eggseparatortoolitem.c +++ b/lib/egg/eggseparatortoolitem.c @@ -10,7 +10,6 @@ static void egg_separator_tool_item_class_init (EggSeparatorToolItemClass*class) static void egg_separator_tool_item_add (GtkContainer *container, GtkWidget *child); -static GtkWidget *egg_separator_tool_item_create_menu_proxy (EggToolItem *self); static GObjectClass *parent_class = NULL; @@ -53,7 +52,6 @@ egg_separator_tool_item_class_init (EggSeparatorToolItemClass *class) toolitem_class = (EggToolItemClass *)class; container_class->add = egg_separator_tool_item_add; - toolitem_class->create_menu_proxy = egg_separator_tool_item_create_menu_proxy; } static void @@ -67,13 +65,6 @@ egg_separator_tool_item_add (GtkContainer *container, GtkWidget *child) g_warning("attempt to add a child to an EggSeparatorToolItem"); } -static GtkWidget * -egg_separator_tool_item_create_menu_proxy (EggToolItem *item) -{ - return gtk_separator_menu_item_new (); -} - - EggToolItem * egg_separator_tool_item_new (void) { diff --git a/lib/egg/eggtoggletoolbutton.c b/lib/egg/eggtoggletoolbutton.c index 5f489bcec..67c76db55 100644 --- a/lib/egg/eggtoggletoolbutton.c +++ b/lib/egg/eggtoggletoolbutton.c @@ -28,6 +28,8 @@ # define _(s) (s) #endif +#define MENU_ID "egg-toggle-tool-button-menu-id" + enum { TOGGLED, LAST_SIGNAL @@ -37,7 +39,7 @@ static void egg_toggle_tool_button_init (EggToggleToolButton *button) static void egg_toggle_tool_button_class_init (EggToggleToolButtonClass *klass); static void egg_toggle_tool_button_finalize (GObject *object); -static GtkWidget *egg_toggle_tool_button_create_menu_proxy (EggToolItem *button); +static gboolean egg_toggle_tool_button_create_menu_proxy (EggToolItem *button); static void button_toggled (GtkWidget *widget, EggToggleToolButton *button); @@ -120,31 +122,34 @@ egg_toggle_tool_button_finalize (GObject *object) (* G_OBJECT_CLASS (parent_class)->finalize) (object); } -static GtkWidget * +static gboolean egg_toggle_tool_button_create_menu_proxy (EggToolItem *item) { + GtkWidget *menu_item = NULL; + EggToggleToolButton *button = EGG_TOGGLE_TOOL_BUTTON (item); gchar *label; label = _egg_tool_button_get_label_text (EGG_TOOL_BUTTON (item)); + + menu_item = gtk_check_menu_item_new_with_mnemonic (label); + g_free (label); - if (button->menu_item) - g_object_remove_weak_pointer (G_OBJECT (button->menu_item), - (gpointer *)&(button->menu_item)); + g_object_ref (menu_item); + gtk_object_sink (GTK_OBJECT (menu_item)); - button->menu_item = gtk_check_menu_item_new_with_mnemonic (label); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (button->menu_item), + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), button->active); - g_signal_connect_object (button->menu_item, "activate", + + g_signal_connect_object (menu_item, "activate", G_CALLBACK (menu_item_activated), EGG_TOOL_BUTTON (button), 0); - g_object_add_weak_pointer (G_OBJECT (button->menu_item), - (gpointer *)&(button->menu_item)); + egg_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item); - g_free (label); + g_object_unref (menu_item); - return button->menu_item; + return TRUE; } static void @@ -173,11 +178,14 @@ button_toggled (GtkWidget *widget, if (toggle_tool_button->active != toggle_active) { + GtkWidget *menu_item; + toggle_tool_button->active = toggle_active; - if (toggle_tool_button->menu_item) - { - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (toggle_tool_button->menu_item), + if ((menu_item = + egg_tool_item_get_proxy_menu_item (EGG_TOOL_ITEM (toggle_tool_button), MENU_ID))) + { + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), toggle_tool_button->active); } diff --git a/lib/egg/eggtoolbar.c b/lib/egg/eggtoolbar.c index f109a4988..eb84db275 100644 --- a/lib/egg/eggtoolbar.c +++ b/lib/egg/eggtoolbar.c @@ -490,7 +490,7 @@ egg_toolbar_init (EggToolbar *toolbar) priv->arrow_button = gtk_toggle_button_new (); g_signal_connect (priv->arrow_button, "button_press_event", G_CALLBACK (egg_toolbar_arrow_button_press), toolbar); - g_signal_connect_after (priv->arrow_button, "clicked", + g_signal_connect (priv->arrow_button, "clicked", G_CALLBACK (egg_toolbar_arrow_button_clicked), toolbar); gtk_button_set_relief (GTK_BUTTON (priv->arrow_button), get_button_relief (toolbar)); @@ -1835,14 +1835,22 @@ menu_deactivated (GtkWidget *menu, EggToolbar *toolbar) } static void +remove_item (GtkWidget *menu_item, gpointer data) +{ + gtk_container_remove (GTK_CONTAINER (menu_item->parent), menu_item); +} + +static void show_menu (EggToolbar *toolbar, GdkEventButton *event) { EggToolbarPrivate *priv = EGG_TOOLBAR_GET_PRIVATE (toolbar); GList *list; - GtkWidget *menu_item; if (priv->menu) - gtk_widget_destroy (GTK_WIDGET (priv->menu)); + { + gtk_container_foreach (GTK_CONTAINER (priv->menu), remove_item, NULL); + gtk_widget_destroy (GTK_WIDGET (priv->menu)); + } priv->menu = GTK_MENU (gtk_menu_new ()); g_signal_connect (priv->menu, "deactivate", G_CALLBACK (menu_deactivated), toolbar); @@ -1853,11 +1861,13 @@ show_menu (EggToolbar *toolbar, GdkEventButton *event) if (TOOLBAR_ITEM_VISIBLE (item) && item->overflow_item) { - menu_item = NULL; - g_signal_emit_by_name (item, "create_menu_proxy", &menu_item); - + GtkWidget *menu_item = egg_tool_item_retrieve_proxy_menu_item (item); + if (menu_item) - gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item); + { + g_assert (GTK_IS_MENU_ITEM (menu_item)); + gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item); + } } } @@ -1873,12 +1883,12 @@ egg_toolbar_arrow_button_clicked (GtkWidget *button, EggToolbar *toolbar) { EggToolbarPrivate *priv = EGG_TOOLBAR_GET_PRIVATE (toolbar); - /* We only get here when the button is clicked with the keybaord, - * because we block mouse button presses by returning TRUE from - * egg_toolbar_arrow_button_press - */ - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button))) + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->arrow_button)) && + (!priv->menu || !GTK_WIDGET_VISIBLE (GTK_WIDGET (priv->menu)))) { + /* We only get here when the button is clicked with the keybaord, + * because mouse button presses result in the menu being shown. + */ show_menu (toolbar, NULL); gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE); } @@ -1889,10 +1899,9 @@ egg_toolbar_arrow_button_press (GtkWidget *button, GdkEventButton *event, EggToolbar *toolbar) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); - show_menu (toolbar, event); - + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); + return TRUE; } diff --git a/lib/egg/eggtoolbutton.c b/lib/egg/eggtoolbutton.c index 14a83f3b8..36408d3ad 100644 --- a/lib/egg/eggtoolbutton.c +++ b/lib/egg/eggtoolbutton.c @@ -35,6 +35,8 @@ # define _(s) (s) #endif +#define MENU_ID "egg-tool-button-menu-id" + enum { CLICKED, LAST_SIGNAL @@ -66,7 +68,7 @@ static void egg_tool_button_get_property (GObject *object, static void egg_tool_button_finalize (GObject *object); static void egg_tool_button_parent_set (GtkWidget *widget, GtkWidget *parent); -static GtkWidget *egg_tool_button_create_menu_proxy (EggToolItem *item); +static gboolean egg_tool_button_create_menu_proxy (EggToolItem *item); static void button_clicked (GtkWidget *widget, EggToolButton *button); @@ -248,6 +250,8 @@ egg_tool_button_construct_contents (EggToolItem *tool_item) gchar *text = _egg_tool_button_get_label_text (button); label = gtk_label_new (text); g_free (text); + + gtk_widget_show (label); } } @@ -267,7 +271,7 @@ egg_tool_button_construct_contents (EggToolItem *tool_item) GtkImageType storage_type = gtk_image_get_storage_type (image); /* FIXME: this seems a bit dubious. We are changing a widget that the - * user passed in. It's probably better to create a new image instead. + * user passed in. It's probably better to create a new image instead. */ if (storage_type == GTK_IMAGE_STOCK) @@ -319,10 +323,6 @@ egg_tool_button_construct_contents (EggToolItem *tool_item) break; } - if (label) - gtk_widget_show (label); - if (icon) - gtk_widget_show (icon); if (box) gtk_widget_show (box); @@ -409,18 +409,21 @@ egg_tool_button_finalize (GObject *object) parent_class->finalize (object); } -static GtkWidget * +static gboolean egg_tool_button_create_menu_proxy (EggToolItem *item) { EggToolButton *button = EGG_TOOL_BUTTON (item); GtkWidget *menu_item; GtkWidget *menu_image = NULL; gchar *label; - + label = _egg_tool_button_get_label_text (button); menu_item = gtk_image_menu_item_new_with_label (label); g_free (label); + g_object_ref (menu_item); + gtk_object_sink (GTK_OBJECT (menu_item)); + if (button->icon_set) { menu_image = gtk_image_new_from_icon_set (button->icon_set, GTK_ICON_SIZE_MENU); @@ -456,7 +459,11 @@ egg_tool_button_create_menu_proxy (EggToolItem *item) EGG_TOOL_BUTTON (button)->button, G_CONNECT_SWAPPED); - return menu_item; + egg_tool_item_set_proxy_menu_item (EGG_TOOL_ITEM (button), MENU_ID, menu_item); + + g_object_unref (menu_item); + + return TRUE; } static void diff --git a/lib/egg/eggtoolitem.c b/lib/egg/eggtoolitem.c index a9142acad..49445d48f 100644 --- a/lib/egg/eggtoolitem.c +++ b/lib/egg/eggtoolitem.c @@ -23,11 +23,14 @@ #include "eggmarshalers.h" #include "eggtoolbar.h" #include <gtk/gtkseparatormenuitem.h> +#include <string.h> #ifndef _ # define _(s) (s) #endif +#define MENU_ID "egg-tool-item-menu-id" + enum { CREATE_MENU_PROXY, TOOLBAR_RECONFIGURED, @@ -66,7 +69,7 @@ static void egg_tool_item_real_set_tooltip (EggToolItem *tool_item, const gchar *tip_text, const gchar *tip_private); -static GtkWidget *egg_tool_item_create_menu_proxy (EggToolItem *item); +static gboolean egg_tool_item_create_menu_proxy (EggToolItem *item); static GObjectClass *parent_class = NULL; @@ -101,21 +104,20 @@ egg_tool_item_get_type (void) } static gboolean -create_proxy_accumulator (GSignalInvocationHint *hint, - GValue *return_accumulator, - const GValue *handler_return, - gpointer user_data) +egg_boolean_handled_accumulator (GSignalInvocationHint *ihint, + GValue *return_accu, + const GValue *handler_return, + gpointer dummy) { - GObject *proxy; gboolean continue_emission; - - proxy = g_value_get_object (handler_return); - g_value_set_object (return_accumulator, proxy); - continue_emission = (proxy == NULL); - + gboolean signal_handled; + + signal_handled = g_value_get_boolean (handler_return); + g_value_set_boolean (return_accu, signal_handled); + continue_emission = !signal_handled; + return continue_emission; } - static void egg_tool_item_class_init (EggToolItemClass *klass) { @@ -153,15 +155,16 @@ egg_tool_item_class_init (EggToolItemClass *klass) _("Whether the toolbar item is visible when the toolbar is in a vertical orientation."), TRUE, G_PARAM_READWRITE)); - toolitem_signals[CREATE_MENU_PROXY] = g_signal_new ("create_menu_proxy", G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (EggToolItemClass, create_menu_proxy), - create_proxy_accumulator, NULL, - _egg_marshal_OBJECT__VOID, - GTK_TYPE_WIDGET, 0); + egg_boolean_handled_accumulator, NULL, /* FIXME: use gtk_boolean_handled() when + * we are added to gtk+ + */ + _egg_marshal_BOOLEAN__VOID, + G_TYPE_BOOLEAN, 0); toolitem_signals[TOOLBAR_RECONFIGURED] = g_signal_new ("toolbar_reconfigured", G_OBJECT_CLASS_TYPE (klass), @@ -362,13 +365,23 @@ egg_tool_item_size_allocate (GtkWidget *widget, } } -static GtkWidget * +static gboolean egg_tool_item_create_menu_proxy (EggToolItem *item) { - if (GTK_BIN (item)->child) - return NULL; - else - return gtk_separator_menu_item_new (); + GtkWidget *menu_item = NULL; + + if (!GTK_BIN (item)->child) + { + menu_item = gtk_separator_menu_item_new(); + g_object_ref (menu_item); + gtk_object_sink (GTK_OBJECT (menu_item)); + } + + egg_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item); + if (menu_item) + g_object_unref (menu_item); + + return TRUE; } EggToolItem * @@ -600,3 +613,50 @@ egg_tool_item_get_visible_vertical (EggToolItem *toolitem) return toolitem->visible_vertical; } + +GtkWidget * +egg_tool_item_retrieve_proxy_menu_item (EggToolItem *tool_item) +{ + gboolean retval; + + g_return_val_if_fail (EGG_IS_TOOL_ITEM (tool_item), NULL); + + g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0, &retval); + + return tool_item->menu_item; +} + +GtkWidget * +egg_tool_item_get_proxy_menu_item (EggToolItem *tool_item, + const gchar *menu_item_id) +{ + g_return_val_if_fail (EGG_IS_TOOL_ITEM (tool_item), NULL); + g_return_val_if_fail (menu_item_id != NULL, NULL); + + if (tool_item->menu_item_id && strcmp (tool_item->menu_item_id, menu_item_id) == 0) + return tool_item->menu_item; + + return NULL; +} + +void +egg_tool_item_set_proxy_menu_item (EggToolItem *tool_item, + const gchar *menu_item_id, + GtkWidget *menu_item) +{ + g_return_if_fail (EGG_IS_TOOL_ITEM (tool_item)); + g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item)); + g_return_if_fail (menu_item_id != NULL); + + if (tool_item->menu_item) + g_object_unref (G_OBJECT (tool_item->menu_item)); + + if (tool_item->menu_item_id) + g_free (tool_item->menu_item_id); + + if (menu_item) + g_object_ref (G_OBJECT (menu_item)); + tool_item->menu_item = menu_item; + + tool_item->menu_item_id = g_strdup (menu_item_id); +} diff --git a/lib/egg/eggtoolitem.h b/lib/egg/eggtoolitem.h index f25ffae89..20f03526b 100644 --- a/lib/egg/eggtoolitem.h +++ b/lib/egg/eggtoolitem.h @@ -24,6 +24,7 @@ #include <gtk/gtkbin.h> #include <gtk/gtktooltips.h> +#include <gtk/gtkmenuitem.h> #define EGG_TYPE_TOOL_ITEM (egg_tool_item_get_type ()) #define EGG_TOOL_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_TOOL_ITEM, EggToolItem)) @@ -51,13 +52,16 @@ struct _EggToolItem guint pack_end : 1; guint use_drag_window : 1; guint overflow_item : 1; + + GtkWidget *menu_item; + gchar *menu_item_id; }; struct _EggToolItemClass { GtkBinClass parent_class; - GtkWidget *(* create_menu_proxy) (EggToolItem *tool_item); + gboolean (* create_menu_proxy) (EggToolItem *tool_item); void (* toolbar_reconfigured) (EggToolItem *tool_item); void (* set_tooltip) (EggToolItem *tool_item, GtkTooltips *tooltips, @@ -68,29 +72,35 @@ struct _EggToolItemClass GType egg_tool_item_get_type (void); EggToolItem *egg_tool_item_new (void); -void egg_tool_item_toolbar_reconfigured (EggToolItem *tool_item); -void egg_tool_item_set_homogeneous (EggToolItem *tool_item, - gboolean homogeneous); -void egg_tool_item_set_expand (EggToolItem *tool_item, - gboolean expand); -void egg_tool_item_set_pack_end (EggToolItem *tool_item, - gboolean pack_end); -void egg_tool_item_set_tooltip (EggToolItem *tool_item, - GtkTooltips *tooltips, - const gchar *tip_text, - const gchar *tip_private); -void egg_tool_item_set_use_drag_window (EggToolItem *toolitem, - gboolean use_drag_window); -void egg_tool_item_set_visible_horizontal (EggToolItem *toolitem, - gboolean visible_horizontal); -gboolean egg_tool_item_get_visible_horizontal (EggToolItem *toolitem); -void egg_tool_item_set_visible_vertical (EggToolItem *toolitem, - gboolean visible_horizontal); -gboolean egg_tool_item_get_visible_vertical (EggToolItem *toolitem); -GtkIconSize egg_tool_item_get_icon_size (EggToolItem *tool_item); -GtkOrientation egg_tool_item_get_orientation (EggToolItem *tool_item); -GtkToolbarStyle egg_tool_item_get_toolbar_style (EggToolItem *tool_item); -GtkReliefStyle egg_tool_item_get_relief_style (EggToolItem *tool_item); +void egg_tool_item_toolbar_reconfigured (EggToolItem *tool_item); +void egg_tool_item_set_homogeneous (EggToolItem *tool_item, + gboolean homogeneous); +void egg_tool_item_set_expand (EggToolItem *tool_item, + gboolean expand); +void egg_tool_item_set_pack_end (EggToolItem *tool_item, + gboolean pack_end); +void egg_tool_item_set_tooltip (EggToolItem *tool_item, + GtkTooltips *tooltips, + const gchar *tip_text, + const gchar *tip_private); +void egg_tool_item_set_use_drag_window (EggToolItem *toolitem, + gboolean use_drag_window); +void egg_tool_item_set_visible_horizontal (EggToolItem *toolitem, + gboolean visible_horizontal); +gboolean egg_tool_item_get_visible_horizontal (EggToolItem *toolitem); +void egg_tool_item_set_visible_vertical (EggToolItem *toolitem, + gboolean visible_horizontal); +gboolean egg_tool_item_get_visible_vertical (EggToolItem *toolitem); +GtkIconSize egg_tool_item_get_icon_size (EggToolItem *tool_item); +GtkOrientation egg_tool_item_get_orientation (EggToolItem *tool_item); +GtkToolbarStyle egg_tool_item_get_toolbar_style (EggToolItem *tool_item); +GtkReliefStyle egg_tool_item_get_relief_style (EggToolItem *tool_item); +GtkWidget * egg_tool_item_retrieve_proxy_menu_item (EggToolItem *tool_item); +GtkWidget * egg_tool_item_get_proxy_menu_item (EggToolItem *tool_item, + const gchar *menu_item_id); +void egg_tool_item_set_proxy_menu_item (EggToolItem *tool_item, + const gchar *menu_item_id, + GtkWidget *menu_item); #endif /* __EGG_TOOL_ITEM_H__ */ |