aboutsummaryrefslogtreecommitdiffstats
path: root/lib/toolbar
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@it.gnome.org>2002-12-31 21:52:44 +0800
committerMarco Pesenti Gritti <mpeseng@src.gnome.org>2002-12-31 21:52:44 +0800
commit6afec98b2cc4c33cd4128d045035a0ec7d43629c (patch)
treefbca72a16cc232b59b16adbe365f29f8bba1b010 /lib/toolbar
parentbeec33b028bdeb5f0da6ed51305f32e3b8041f6e (diff)
downloadgsoc2013-epiphany-6afec98b2cc4c33cd4128d045035a0ec7d43629c.tar
gsoc2013-epiphany-6afec98b2cc4c33cd4128d045035a0ec7d43629c.tar.gz
gsoc2013-epiphany-6afec98b2cc4c33cd4128d045035a0ec7d43629c.tar.bz2
gsoc2013-epiphany-6afec98b2cc4c33cd4128d045035a0ec7d43629c.tar.lz
gsoc2013-epiphany-6afec98b2cc4c33cd4128d045035a0ec7d43629c.tar.xz
gsoc2013-epiphany-6afec98b2cc4c33cd4128d045035a0ec7d43629c.tar.zst
gsoc2013-epiphany-6afec98b2cc4c33cd4128d045035a0ec7d43629c.zip
Resync with galeon.
2002-12-31 Marco Pesenti Gritti <marco@it.gnome.org> * embed/mozilla/FilePicker.cpp: * embed/mozilla/FilePicker.h: * embed/mozilla/mozilla-embed-shell.cpp: Resync with galeon. * data/epiphany.schemas.in: * lib/ephy-bonobo-extensions.c: (ephy_bonobo_add_numbered_widget): * lib/ephy-bonobo-extensions.h: * lib/toolbar/Makefile.am: * lib/toolbar/ephy-tbi-std-toolitem.c: (ephy_tbi_std_toolitem_init), (ephy_tbi_std_toolitem_get_icon_impl), (ephy_tbi_std_toolitem_get_name_human_impl), (ephy_tbi_std_toolitem_to_string_impl), (ephy_tbi_std_toolitem_add_to_bonobo_tb_impl), (ephy_tbi_std_toolitem_parse_properties_impl), (ephy_tbi_std_toolitem_set_item): * lib/toolbar/ephy-tbi-std-toolitem.h: * lib/toolbar/ephy-toolbar-item-factory.c: (ephy_tb_item_factory_init), (ephy_toolbar_item_create_from_string), (ephy_toolbar_item_register_type): * lib/toolbar/ephy-toolbar-item-factory.h: * src/Makefile.am: * src/toolbar.c: (toolbar_class_init), (toolbar_set_property), (toolbar_get_widgets), (toolbar_init), (toolbar_finalize), (toolbar_navigation_button_set_sensitive), (toolbar_button_set_sensitive): * src/window-commands.c: Resync with galeon. Now we use a widget for navigation buttons.
Diffstat (limited to 'lib/toolbar')
-rw-r--r--lib/toolbar/Makefile.am4
-rw-r--r--lib/toolbar/ephy-tb-button.c746
-rw-r--r--lib/toolbar/ephy-tb-button.h79
-rw-r--r--lib/toolbar/ephy-tbi-std-toolitem.c112
-rw-r--r--lib/toolbar/ephy-tbi-std-toolitem.h6
-rw-r--r--lib/toolbar/ephy-toolbar-item-factory.c80
-rw-r--r--lib/toolbar/ephy-toolbar-item-factory.h4
7 files changed, 904 insertions, 127 deletions
diff --git a/lib/toolbar/Makefile.am b/lib/toolbar/Makefile.am
index a6affaa04..eb2bcf687 100644
--- a/lib/toolbar/Makefile.am
+++ b/lib/toolbar/Makefile.am
@@ -38,4 +38,6 @@ libephytoolbar_la_SOURCES = \
ephy-toolbar-tree-model.h \
ephy-toolbar-tree-model.c \
ephy-toolbar-editor.h \
- ephy-toolbar-editor.c
+ ephy-toolbar-editor.c \
+ ephy-tb-button.c \
+ ephy-tb-button.h
diff --git a/lib/toolbar/ephy-tb-button.c b/lib/toolbar/ephy-tb-button.c
new file mode 100644
index 000000000..4b251a094
--- /dev/null
+++ b/lib/toolbar/ephy-tb-button.c
@@ -0,0 +1,746 @@
+/*
+ * Copyright (C) 2002 Ricardo Fernández Pascual
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "ephy-tb-button.h"
+#include "ephy-gobject-misc.h"
+#include "ephy-gui.h"
+#include "ephy-marshal.h"
+#include "eel-gconf-extensions.h"
+
+#include <libgnome/gnome-i18n.h>
+#include <gtk/gtklabel.h>
+#include <gtk/gtkalignment.h>
+#include <gtk/gtktoolbar.h>
+#include <bonobo/bonobo-ui-toolbar.h>
+#include <string.h>
+
+#define NOT_IMPLEMENTED g_warning ("not implemented: " G_STRLOC);
+//#define DEBUG_MSG(x) g_print x
+#define DEBUG_MSG(x)
+
+/**
+ * Private data
+ */
+struct _EphyTbButtonPrivate
+{
+ gchar *label;
+ GtkWidget *image;
+ gboolean use_stock;
+ gchar *tooltip_text;
+ GtkMenu *menu;
+ GtkWidget *arrow_widget;
+ gboolean sensitive;
+
+ GtkWidget *button;
+ GtkBox *button_box;
+ GtkLabel *label_wid;
+ gboolean priority;
+
+ gboolean in_bonobo_toobar;
+
+ GtkReliefStyle button_relief;
+ GtkOrientation orientation;
+ GtkToolbarStyle style_gtk;
+ BonoboUIToolbarStyle style_bonobo;
+ GtkIconSize icon_size; // TODO
+ gboolean show_tooltips;
+ GtkTooltips *tooltips;
+};
+
+/**
+ * Private functions, only availble from this file
+ */
+static void ephy_tb_button_class_init (EphyTbButtonClass *klass);
+static void ephy_tb_button_init (EphyTbButton *b);
+static void ephy_tb_button_finalize_impl (GObject *o);
+static void ephy_tb_button_build (EphyTbButton *b);
+static void ephy_tb_button_empty (EphyTbButton *b);
+static void ephy_tb_button_parent_set_cb (GtkWidget *widget, GtkObject *old_parent,
+ EphyTbButton *tb);
+static void ephy_tb_button_gtk_orientation_changed_cb (GtkToolbar *toolbar, GtkOrientation orientation,
+ EphyTbButton *b);
+static void ephy_tb_button_gtk_style_changed_cb (GtkToolbar *toolbar, GtkToolbarStyle style,
+ EphyTbButton *b);
+static void ephy_tb_button_bonobo_set_orientation_cb (BonoboUIToolbar *toolbar, GtkOrientation orientation,
+ EphyTbButton *b);
+static void ephy_tb_button_bonobo_set_style_cb (BonoboUIToolbar *toolbar, EphyTbButton *b);
+static gboolean ephy_tb_button_arrow_key_press_event_cb (GtkWidget *widget, GdkEventKey *event,
+ EphyTbButton *b);
+static gboolean ephy_tb_button_arrow_button_press_event_cb (GtkWidget *widget, GdkEventButton *event,
+ EphyTbButton *b);
+static gboolean ephy_tb_button_button_button_press_event_cb (GtkWidget *widget, GdkEventButton *event,
+ EphyTbButton *b);
+static void ephy_tb_button_button_popup_menu_cb (GtkWidget *w, EphyTbButton *b);
+static void ephy_tb_button_menu_deactivated_cb (GtkMenuShell *ms, EphyTbButton *b);
+
+
+static gpointer gtk_hbox_class;
+
+enum EphyTbButtonSignalsEnum {
+ EPHY_TB_BUTTON_MENU_ACTIVATED,
+ EPHY_TB_BUTTON_LAST_SIGNAL
+};
+static gint EphyTbButtonSignals[EPHY_TB_BUTTON_LAST_SIGNAL];
+
+/**
+ * TbButton object
+ */
+
+MAKE_GET_TYPE (ephy_tb_button, "EphyTbButton", EphyTbButton, ephy_tb_button_class_init,
+ ephy_tb_button_init, GTK_TYPE_HBOX);
+
+static void
+ephy_tb_button_class_init (EphyTbButtonClass *klass)
+{
+ G_OBJECT_CLASS (klass)->finalize = ephy_tb_button_finalize_impl;
+ gtk_hbox_class = g_type_class_peek_parent (klass);
+
+ EphyTbButtonSignals[EPHY_TB_BUTTON_MENU_ACTIVATED] = g_signal_new (
+ "menu-activated", G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_RUN_CLEANUP,
+ G_STRUCT_OFFSET (EphyTbButtonClass, menu_activated),
+ NULL, NULL,
+ ephy_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+}
+
+static void
+ephy_tb_button_init (EphyTbButton *tb)
+{
+ EphyTbButtonPrivate *p = g_new0 (EphyTbButtonPrivate, 1);
+ tb->priv = p;
+ p->label = g_strdup ("");
+ p->tooltip_text = g_strdup ("");
+
+ p->button_relief = GTK_RELIEF_NORMAL;
+ p->orientation = GTK_ORIENTATION_HORIZONTAL;
+ p->style_gtk = GTK_TOOLBAR_BOTH_HORIZ;
+ p->style_bonobo = BONOBO_UI_TOOLBAR_STYLE_PRIORITY_TEXT;
+ p->icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
+ p->show_tooltips = TRUE;
+
+ g_signal_connect (tb, "parent-set",
+ G_CALLBACK (ephy_tb_button_parent_set_cb), tb);
+}
+
+EphyTbButton *
+ephy_tb_button_new (void)
+{
+ EphyTbButton *ret = g_object_new (EPHY_TYPE_TB_BUTTON, NULL);
+ return ret;
+}
+
+static void
+ephy_tb_button_finalize_impl (GObject *o)
+{
+ EphyTbButton *it = EPHY_TB_BUTTON (o);
+ EphyTbButtonPrivate *p = it->priv;
+
+ ephy_tb_button_empty (it);
+
+ if (p->image)
+ {
+ g_object_unref (p->image);
+ }
+
+ if (p->tooltips)
+ {
+ g_object_unref (p->tooltips);
+ }
+
+ if (p->menu)
+ {
+ g_object_unref (p->menu);
+ }
+
+ if (p->arrow_widget)
+ {
+ g_object_unref (p->arrow_widget);
+ }
+
+ g_free (p);
+
+ DEBUG_MSG (("EphyTbButton finalized\n"));
+
+ G_OBJECT_CLASS (gtk_hbox_class)->finalize (o);
+}
+
+void
+ephy_tb_button_set_label (EphyTbButton *b, const gchar *text)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ g_free (p->label);
+ p->label = g_strdup (text);
+ DEBUG_MSG (("EphyTbButton label set to '%s'\n", p->label));
+ if (!p->label_wid || p->use_stock)
+ {
+ ephy_tb_button_build (b);
+ }
+ else
+ {
+ gtk_label_set_text (p->label_wid, p->label);
+ }
+}
+
+void
+ephy_tb_button_set_tooltip_text (EphyTbButton *b, const gchar *text)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ g_free (p->tooltip_text);
+ p->tooltip_text = g_strdup (text);
+
+ if (!p->tooltips || !p->button)
+ {
+ ephy_tb_button_build (b);
+ }
+ else
+ {
+ gtk_tooltips_set_tip (p->tooltips, p->button,
+ p->tooltip_text, p->tooltip_text);
+ }
+}
+
+/* this function comes directly from gtktoolbar.c */
+static gchar *
+elide_underscores (const gchar *original)
+{
+ gchar *q, *result;
+ const gchar *p;
+ gboolean last_underscore;
+
+ q = result = g_malloc (strlen (original) + 1);
+ last_underscore = FALSE;
+
+ for (p = original; *p; p++)
+ {
+ if (!last_underscore && *p == '_')
+ {
+ last_underscore = TRUE;
+ }
+ else
+ {
+ last_underscore = FALSE;
+ *q++ = *p;
+ }
+ }
+
+ *q = '\0';
+
+ return result;
+}
+
+static void
+ephy_tb_button_build (EphyTbButton *b)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ GtkWidget *align;
+ GtkWidget *image;
+ GtkStockItem stock_item;
+ gboolean really_use_stock = p->use_stock && gtk_stock_lookup (p->label, &stock_item);
+ gboolean show_image = p->label[0] == '\0'
+ || (p->in_bonobo_toobar && p->style_bonobo != BONOBO_UI_TOOLBAR_STYLE_TEXT_ONLY)
+ || (!p->in_bonobo_toobar && p->style_gtk != GTK_TOOLBAR_TEXT);
+ gboolean show_label = !show_image
+ || (p->priority && ((p->in_bonobo_toobar && p->style_bonobo == BONOBO_UI_TOOLBAR_STYLE_PRIORITY_TEXT)
+ || (!p->in_bonobo_toobar && p->style_gtk == GTK_TOOLBAR_BOTH_HORIZ)))
+ || (!p->in_bonobo_toobar
+ && (p->style_gtk == GTK_TOOLBAR_BOTH
+ || p->style_gtk == GTK_TOOLBAR_TEXT
+ /* CHECK: what about GTK_TOOLBAR_BOTH_HORIZ? */ ))
+ || (p->in_bonobo_toobar
+ && (p->style_bonobo == BONOBO_UI_TOOLBAR_STYLE_ICONS_AND_TEXT
+ || p->style_bonobo == BONOBO_UI_TOOLBAR_STYLE_TEXT_ONLY));
+
+ ephy_tb_button_empty (b);
+
+ if (!p->button)
+ {
+ p->button = gtk_button_new ();
+ g_object_ref (p->button);
+ gtk_widget_show (p->button);
+ gtk_box_pack_start_defaults (GTK_BOX (b), p->button);
+ }
+
+ gtk_button_set_relief (GTK_BUTTON (p->button), p->button_relief);
+ gtk_widget_set_sensitive (p->button, p->sensitive);
+ if (p->tooltips)
+ {
+ gtk_tooltips_set_tip (p->tooltips, p->button,
+ p->tooltip_text, p->tooltip_text);
+ }
+ g_signal_connect (p->button, "button_press_event",
+ G_CALLBACK (ephy_tb_button_button_button_press_event_cb), b);
+ g_signal_connect (p->button, "popup_menu",
+ G_CALLBACK (ephy_tb_button_button_popup_menu_cb), b);
+
+ align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
+ gtk_widget_show (align);
+ gtk_container_add (GTK_CONTAINER (p->button), align);
+
+ if ((p->in_bonobo_toobar && p->style_bonobo == BONOBO_UI_TOOLBAR_STYLE_ICONS_AND_TEXT)
+ || (!p->in_bonobo_toobar && p->style_gtk == GTK_TOOLBAR_BOTH)
+ || p->orientation == GTK_ORIENTATION_VERTICAL)
+ {
+ p->button_box = GTK_BOX (gtk_vbox_new (FALSE, 2));
+ }
+ else
+ {
+ p->button_box = GTK_BOX (gtk_hbox_new (FALSE, 2));
+ }
+ g_object_ref (p->button_box);
+ gtk_widget_show (GTK_WIDGET (p->button_box));
+ gtk_container_add (GTK_CONTAINER (align), GTK_WIDGET (p->button_box));
+
+ if (!p->image && really_use_stock && show_image)
+ {
+ image = gtk_image_new_from_stock (p->label, p->icon_size);
+ }
+ else
+ {
+ image = p->image;
+ }
+
+ if (image)
+ {
+ if (show_image)
+ {
+ gtk_box_pack_start_defaults (p->button_box, GTK_WIDGET (image));
+ gtk_widget_show (image);
+ }
+ }
+ else
+ {
+ show_label = TRUE;
+ }
+
+ if (show_label)
+ {
+ p->label_wid = GTK_LABEL (gtk_label_new (p->label));
+ g_object_ref (p->label_wid);
+
+ if (really_use_stock)
+ {
+ gchar *l = elide_underscores (stock_item.label);
+ gtk_label_set_text (p->label_wid, l);
+ g_free (l);
+ }
+
+ gtk_widget_show (GTK_WIDGET (p->label_wid));
+ gtk_box_pack_end_defaults (p->button_box, GTK_WIDGET (p->label_wid));
+ }
+
+ DEBUG_MSG (("EphyTbButton built, label='%s'\n", p->label));
+}
+
+void
+ephy_tb_button_set_priority (EphyTbButton *b, gboolean priority)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ if (p->priority != priority)
+ {
+ p->priority = priority;
+ ephy_tb_button_build (b);
+ }
+}
+
+void
+ephy_tb_button_set_image (EphyTbButton *b, GtkWidget *image)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ if (p->image)
+ {
+ g_object_unref (p->image);
+ }
+ p->image = image ? g_object_ref (image) : NULL;
+ ephy_tb_button_build (b);
+}
+
+void
+ephy_tb_button_set_show_arrow (EphyTbButton *b, gboolean value)
+{
+ EphyTbButtonPrivate *p = b->priv;
+
+ if (p->arrow_widget && !value)
+ {
+ if (p->arrow_widget->parent == GTK_WIDGET (b))
+ {
+ gtk_container_remove (GTK_CONTAINER (b), p->arrow_widget);
+ }
+ g_object_unref (p->arrow_widget);
+ p->arrow_widget = NULL;
+ }
+ else if (!p->arrow_widget && value)
+ {
+ p->arrow_widget = gtk_toggle_button_new ();
+ gtk_button_set_relief (GTK_BUTTON (p->arrow_widget), GTK_RELIEF_NONE);
+
+ gtk_container_add (GTK_CONTAINER (p->arrow_widget),
+ gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT));
+
+ g_object_ref (p->arrow_widget);
+ gtk_object_sink (GTK_OBJECT (p->arrow_widget));
+
+ g_signal_connect (p->arrow_widget, "key_press_event",
+ G_CALLBACK (ephy_tb_button_arrow_key_press_event_cb),
+ b);
+
+ g_signal_connect (p->arrow_widget, "button_press_event",
+ G_CALLBACK (ephy_tb_button_arrow_button_press_event_cb),
+ b);
+
+ gtk_widget_show_all (p->arrow_widget);
+ gtk_box_pack_end_defaults (GTK_BOX (b), p->arrow_widget);
+ gtk_widget_set_sensitive (p->arrow_widget, value);
+ }
+}
+
+void
+ephy_tb_button_set_enable_menu (EphyTbButton *b, gboolean value)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ if (value && !p->menu)
+ {
+ p->menu = GTK_MENU (gtk_menu_new ());
+ g_signal_connect (p->menu, "deactivate",
+ G_CALLBACK (ephy_tb_button_menu_deactivated_cb), b);
+ }
+ else if (!value && p->menu)
+ {
+ g_object_unref (p->menu);
+ p->menu = FALSE;
+ }
+
+}
+
+GtkMenuShell *
+ephy_tb_button_get_menu (EphyTbButton *b)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ return p->menu ? GTK_MENU_SHELL (p->menu) : NULL;
+}
+
+GtkButton *
+ephy_tb_button_get_button (EphyTbButton *b)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ if (!p->button)
+ {
+ ephy_tb_button_build (b);
+ }
+ return GTK_BUTTON (p->button);
+}
+
+void
+ephy_tb_button_set_use_stock (EphyTbButton *b, gboolean value)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ if (value != p->use_stock)
+ {
+ p->use_stock = value;
+ ephy_tb_button_build (b);
+ }
+}
+
+static void
+ephy_tb_button_empty (EphyTbButton *b)
+{
+ EphyTbButtonPrivate *p = b->priv;
+
+ if (p->button)
+ {
+ if (GTK_BIN (p->button)->child)
+ {
+ gtk_container_remove (GTK_CONTAINER (p->button), GTK_BIN (p->button)->child);
+ }
+ }
+
+ if (p->button_box)
+ {
+ g_object_unref (p->button_box);
+ p->button_box = NULL;
+ }
+
+ if (p->label_wid)
+ {
+ g_object_unref (p->label_wid);
+ p->label_wid = NULL;
+ }
+}
+
+static void
+ephy_tb_button_parent_set_cb (GtkWidget *widget, GtkObject *old_parent, EphyTbButton *tb)
+{
+ EphyTbButtonPrivate *p = tb->priv;
+ GtkWidget *new_parent = widget->parent;
+
+ DEBUG_MSG (("EphyTbButton parent changed (widget=%p, button=%p, old=%p, new=%p)\n",
+ widget, tb, old_parent, new_parent));
+
+ if (new_parent)
+ {
+ GtkToolbar *gtktb = NULL;
+ BonoboUIToolbar *btb = NULL;
+ while (new_parent && !gtktb && !btb)
+ {
+ DEBUG_MSG (("new_parent ia a %s\n", g_type_name_from_instance ((void *) new_parent)));
+
+ if (GTK_IS_TOOLBAR (new_parent))
+ {
+ gtktb = GTK_TOOLBAR (new_parent);
+ }
+ else if (BONOBO_IS_UI_TOOLBAR (new_parent))
+ {
+ btb = BONOBO_UI_TOOLBAR (new_parent);
+ }
+ else
+ {
+ g_signal_connect (new_parent, "parent_set",
+ G_CALLBACK (ephy_tb_button_parent_set_cb), tb);
+ }
+ new_parent = new_parent->parent;
+ }
+
+ if (gtktb)
+ {
+ DEBUG_MSG (("EphyTbButton getting style from a GtkToolbar (%p)\n", gtktb));
+ p->in_bonobo_toobar = FALSE;
+
+ gtk_widget_ensure_style (GTK_WIDGET (gtktb));
+ gtk_widget_style_get (GTK_WIDGET (gtktb), "button_relief", &p->button_relief, NULL);
+
+ p->orientation = gtk_toolbar_get_orientation (gtktb);
+ p->style_gtk = gtk_toolbar_get_style (gtktb);
+ p->icon_size = gtk_toolbar_get_icon_size (gtktb);
+ p->show_tooltips = gtk_toolbar_get_tooltips (gtktb);
+
+ if (p->tooltips)
+ {
+ g_object_unref (p->tooltips);
+ }
+ p->tooltips = gtk_tooltips_new ();
+ if (p->show_tooltips)
+ {
+ gtk_tooltips_enable (p->tooltips);
+ }
+ else
+ {
+ gtk_tooltips_disable (p->tooltips);
+ }
+ g_object_ref (p->tooltips);
+ gtk_object_sink (GTK_OBJECT (p->tooltips));
+
+ g_signal_connect (gtktb, "orientation-changed",
+ G_CALLBACK (ephy_tb_button_gtk_orientation_changed_cb), tb);
+ g_signal_connect (gtktb, "style-changed",
+ G_CALLBACK (ephy_tb_button_gtk_style_changed_cb), tb);
+
+ ephy_tb_button_build (tb);
+ }
+
+ if (btb)
+ {
+ DEBUG_MSG (("EphyTbButton getting style from a BonoboUIToolbar (%p)\n", btb));
+ p->in_bonobo_toobar = TRUE;
+
+ p->button_relief = GTK_RELIEF_NONE;
+
+ p->orientation = bonobo_ui_toolbar_get_orientation (btb);
+ p->style_bonobo = bonobo_ui_toolbar_get_style (btb);
+ //p->icon_size = ???;
+ p->show_tooltips = TRUE;
+
+ if (p->tooltips)
+ {
+ g_object_unref (p->tooltips);
+ }
+ p->tooltips = bonobo_ui_toolbar_get_tooltips (btb);
+ g_object_ref (p->tooltips);
+
+ g_signal_connect (btb, "set-orientation",
+ G_CALLBACK (ephy_tb_button_bonobo_set_orientation_cb), tb);
+ g_signal_connect (btb, "set-style",
+ G_CALLBACK (ephy_tb_button_bonobo_set_style_cb), tb);
+
+ ephy_tb_button_build (tb);
+ }
+ }
+ else
+ {
+ while (old_parent)
+ {
+ g_signal_handlers_disconnect_matched (old_parent, G_SIGNAL_MATCH_DATA,
+ 0, 0, NULL, NULL, tb);
+ if (GTK_IS_WIDGET (old_parent))
+ {
+ old_parent = GTK_WIDGET (old_parent)->parent
+ ? GTK_OBJECT (GTK_WIDGET (old_parent)->parent)
+ : NULL;
+ }
+ else
+ {
+ old_parent = NULL;
+ }
+ }
+ }
+}
+
+static void
+ephy_tb_button_gtk_orientation_changed_cb (GtkToolbar *toolbar, GtkOrientation orientation, EphyTbButton *b)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ if (p->orientation != orientation)
+ {
+ p->orientation = orientation;
+ ephy_tb_button_build (b);
+ }
+}
+
+static void
+ephy_tb_button_gtk_style_changed_cb (GtkToolbar *toolbar, GtkToolbarStyle style, EphyTbButton *b)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ if (p->style_gtk != style)
+ {
+ p->style_gtk = style;
+ ephy_tb_button_build (b);
+ }
+}
+
+static void
+ephy_tb_button_bonobo_set_orientation_cb (BonoboUIToolbar *toolbar, GtkOrientation orientation, EphyTbButton *b)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ if (p->orientation != orientation)
+ {
+ p->orientation = orientation;
+ ephy_tb_button_build (b);
+ }
+}
+
+static void
+ephy_tb_button_bonobo_set_style_cb (BonoboUIToolbar *toolbar, EphyTbButton *b)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ BonoboUIToolbarStyle style = bonobo_ui_toolbar_get_style (toolbar);
+ if (style != p->style_bonobo)
+ {
+ p->style_bonobo = style;
+ ephy_tb_button_build (b);
+ }
+}
+
+static void
+ephy_tb_button_popup_menu_under_arrow (EphyTbButton *b, GdkEventButton *event)
+{
+ EphyTbButtonPrivate *p = b->priv;
+
+ if (p->menu)
+ {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (p->arrow_widget), TRUE);
+ g_signal_emit (b, EphyTbButtonSignals[EPHY_TB_BUTTON_MENU_ACTIVATED], 0);
+ gtk_menu_popup (p->menu, NULL, NULL, ephy_gui_menu_position_under_widget, p->arrow_widget,
+ event ? event->button : 0,
+ event ? event->time : gtk_get_current_event_time ());
+ }
+}
+
+static void
+ephy_tb_button_menu_deactivated_cb (GtkMenuShell *ms, EphyTbButton *b)
+{
+ EphyTbButtonPrivate *p = b->priv;
+ if (p->arrow_widget)
+ {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (p->arrow_widget), FALSE);
+ }
+}
+
+static gboolean
+ephy_tb_button_arrow_button_press_event_cb (GtkWidget *widget, GdkEventButton *event, EphyTbButton *b)
+{
+ ephy_tb_button_popup_menu_under_arrow (b, event);
+ return TRUE;
+}
+
+static gboolean
+ephy_tb_button_arrow_key_press_event_cb (GtkWidget *widget, GdkEventKey *event, EphyTbButton *b)
+{
+ if (event->keyval == GDK_space
+ || event->keyval == GDK_KP_Space
+ || event->keyval == GDK_Return
+ || event->keyval == GDK_KP_Enter
+ || event->keyval == GDK_Menu)
+ {
+ ephy_tb_button_popup_menu_under_arrow (b, NULL);
+ }
+
+ return FALSE;
+}
+
+static gboolean
+ephy_tb_button_button_button_press_event_cb (GtkWidget *widget, GdkEventButton *event,
+ EphyTbButton *b)
+{
+ EphyTbButtonPrivate *p = b->priv;
+
+ if (event->button == 3 && p->menu)
+ {
+ g_signal_emit (b, EphyTbButtonSignals[EPHY_TB_BUTTON_MENU_ACTIVATED], 0);
+ gtk_menu_popup (p->menu, NULL, NULL, NULL, b,
+ event ? event->button : 0,
+ event ? event->time : gtk_get_current_event_time ());
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+ephy_tb_button_button_popup_menu_cb (GtkWidget *w, EphyTbButton *b)
+{
+ EphyTbButtonPrivate *p = b->priv;
+
+ g_signal_emit (b, EphyTbButtonSignals[EPHY_TB_BUTTON_MENU_ACTIVATED], 0);
+ gtk_menu_popup (p->menu, NULL, NULL,
+ ephy_gui_menu_position_under_widget, b, 0, gtk_get_current_event_time ());
+}
+
+void
+ephy_tb_button_set_sensitivity (EphyTbButton *b, gboolean value)
+{
+ EphyTbButtonPrivate *p = b->priv;
+
+ p->sensitive = value;
+
+ if (!p->button)
+ {
+ ephy_tb_button_build (b);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (p->button, value);
+ if (p->arrow_widget)
+ {
+ gtk_widget_set_sensitive (p->arrow_widget, value);
+ }
+ }
+}
+
diff --git a/lib/toolbar/ephy-tb-button.h b/lib/toolbar/ephy-tb-button.h
new file mode 100644
index 000000000..5d3d9616a
--- /dev/null
+++ b/lib/toolbar/ephy-tb-button.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2002 Ricardo Fernández Pascual
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ */
+
+#ifndef EPHY_TB_BUTTON_H
+#define EPHY_TB_BUTTON_H
+
+#include <gtk/gtkhbox.h>
+#include <gtk/gtkmenushell.h>
+#include <gtk/gtkbutton.h>
+
+G_BEGIN_DECLS
+
+/* object forward declarations */
+
+typedef struct _EphyTbButton EphyTbButton;
+typedef struct _EphyTbButtonClass EphyTbButtonClass;
+typedef struct _EphyTbButtonPrivate EphyTbButtonPrivate;
+
+/**
+ * TbButton object
+ */
+
+#define EPHY_TYPE_TB_BUTTON (ephy_tb_button_get_type())
+#define EPHY_TB_BUTTON(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EPHY_TYPE_TB_BUTTON,\
+ EphyTbButton))
+#define EPHY_TB_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EPHY_TYPE_TB_BUTTON,\
+ EphyTbButtonClass))
+#define EPHY_IS_TB_BUTTON(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EPHY_TYPE_TB_BUTTON))
+#define EPHY_IS_TB_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EPHY_TYPE_TB_BUTTON))
+#define EPHY_TB_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_TB_BUTTON,\
+ EphyTbButtonClass))
+
+struct _EphyTbButtonClass
+{
+ GtkHBoxClass parent_class;
+
+ void (*menu_activated) (EphyTbButton *b);
+};
+
+/* Remember: fields are public read-only */
+struct _EphyTbButton
+{
+ GtkHBox parent_object;
+ EphyTbButtonPrivate *priv;
+};
+
+/* this class is abstract */
+
+GType ephy_tb_button_get_type (void);
+EphyTbButton * ephy_tb_button_new (void);
+void ephy_tb_button_set_label (EphyTbButton *b, const gchar *text);
+void ephy_tb_button_set_use_stock (EphyTbButton *b, gboolean value);
+void ephy_tb_button_set_priority (EphyTbButton *b, gboolean priority);
+void ephy_tb_button_set_image (EphyTbButton *b, GtkWidget *image);
+void ephy_tb_button_set_tooltip_text (EphyTbButton *b, const gchar *text);
+void ephy_tb_button_set_show_arrow (EphyTbButton *b, gboolean value);
+void ephy_tb_button_set_enable_menu (EphyTbButton *b, gboolean value);
+GtkMenuShell * ephy_tb_button_get_menu (EphyTbButton *b);
+GtkButton * ephy_tb_button_get_button (EphyTbButton *b);
+void ephy_tb_button_set_sensitivity (EphyTbButton *b, gboolean value);
+
+G_END_DECLS
+
+#endif
diff --git a/lib/toolbar/ephy-tbi-std-toolitem.c b/lib/toolbar/ephy-tbi-std-toolitem.c
index deb468ecb..4b7f3864c 100644
--- a/lib/toolbar/ephy-tbi-std-toolitem.c
+++ b/lib/toolbar/ephy-tbi-std-toolitem.c
@@ -97,7 +97,7 @@ ephy_tbi_std_toolitem_init (EphyTbiStdToolitem *tb)
EphyTbiStdToolitemPrivate *p = g_new0 (EphyTbiStdToolitemPrivate, 1);
tb->priv = p;
- p->item = EPHY_TBI_STD_TOOLITEM_BACK;
+ p->item = EPHY_TBI_STD_TOOLITEM_STOP;
}
EphyTbiStdToolitem *
@@ -137,31 +137,16 @@ ephy_tbi_std_toolitem_get_icon_impl (EphyTbItem *i)
{
EphyTbiStdToolitemPrivate *p = EPHY_TBI_STD_TOOLITEM (i)->priv;
- static GdkPixbuf *pb_up = NULL;
- static GdkPixbuf *pb_back = NULL;
- static GdkPixbuf *pb_forward = NULL;
static GdkPixbuf *pb_stop = NULL;
static GdkPixbuf *pb_reload = NULL;
static GdkPixbuf *pb_home = NULL;
static GdkPixbuf *pb_go = NULL;
static GdkPixbuf *pb_new = NULL;
-
- if (!pb_up)
+
+ if (!pb_stop)
{
/* what's the easier way? */
GtkWidget *b = gtk_spin_button_new_with_range (0, 1, 0.5);
- pb_up = gtk_widget_render_icon (b,
- GTK_STOCK_GO_UP,
- GTK_ICON_SIZE_SMALL_TOOLBAR,
- NULL);
- pb_back = gtk_widget_render_icon (b,
- GTK_STOCK_GO_BACK,
- GTK_ICON_SIZE_SMALL_TOOLBAR,
- NULL);
- pb_forward = gtk_widget_render_icon (b,
- GTK_STOCK_GO_FORWARD,
- GTK_ICON_SIZE_SMALL_TOOLBAR,
- NULL);
pb_stop = gtk_widget_render_icon (b,
GTK_STOCK_STOP,
GTK_ICON_SIZE_SMALL_TOOLBAR,
@@ -187,15 +172,6 @@ ephy_tbi_std_toolitem_get_icon_impl (EphyTbItem *i)
switch (p->item)
{
- case EPHY_TBI_STD_TOOLITEM_BACK:
- return g_object_ref (pb_back);
- break;
- case EPHY_TBI_STD_TOOLITEM_FORWARD:
- return g_object_ref (pb_forward);
- break;
- case EPHY_TBI_STD_TOOLITEM_UP:
- return g_object_ref (pb_up);
- break;
case EPHY_TBI_STD_TOOLITEM_STOP:
return g_object_ref (pb_stop);
break;
@@ -211,6 +187,9 @@ ephy_tbi_std_toolitem_get_icon_impl (EphyTbItem *i)
case EPHY_TBI_STD_TOOLITEM_NEW:
return g_object_ref (pb_new);
break;
+ case EPHY_TBI_STD_TOOLITEM_ERROR:
+ return NULL;
+ break;
default:
g_assert_not_reached ();
return NULL;
@@ -225,15 +204,6 @@ ephy_tbi_std_toolitem_get_name_human_impl (EphyTbItem *i)
switch (p->item)
{
- case EPHY_TBI_STD_TOOLITEM_BACK:
- ret = _("Back");
- break;
- case EPHY_TBI_STD_TOOLITEM_FORWARD:
- ret = _("Forward");
- break;
- case EPHY_TBI_STD_TOOLITEM_UP:
- ret = _("Up");
- break;
case EPHY_TBI_STD_TOOLITEM_STOP:
ret = _("Stop");
break;
@@ -249,6 +219,9 @@ ephy_tbi_std_toolitem_get_name_human_impl (EphyTbItem *i)
case EPHY_TBI_STD_TOOLITEM_NEW:
ret = _("New");
break;
+ case EPHY_TBI_STD_TOOLITEM_ERROR:
+ ret = "Erroneous button";
+ break;
default:
g_assert_not_reached ();
ret = "unknown";
@@ -267,15 +240,6 @@ ephy_tbi_std_toolitem_to_string_impl (EphyTbItem *i)
switch (p->item)
{
- case EPHY_TBI_STD_TOOLITEM_BACK:
- sitem = "back";
- break;
- case EPHY_TBI_STD_TOOLITEM_FORWARD:
- sitem = "forward";
- break;
- case EPHY_TBI_STD_TOOLITEM_UP:
- sitem = "up";
- break;
case EPHY_TBI_STD_TOOLITEM_STOP:
sitem = "stop";
break;
@@ -291,6 +255,9 @@ ephy_tbi_std_toolitem_to_string_impl (EphyTbItem *i)
case EPHY_TBI_STD_TOOLITEM_NEW:
sitem = "new";
break;
+ case EPHY_TBI_STD_TOOLITEM_ERROR:
+ sitem = "error";
+ break;
default:
g_assert_not_reached ();
sitem = "unknown";
@@ -330,28 +297,6 @@ ephy_tbi_std_toolitem_add_to_bonobo_tb_impl (EphyTbItem *i, BonoboUIComponent *u
switch (p->item)
{
- case EPHY_TBI_STD_TOOLITEM_BACK:
- xml_item = g_strdup_printf
- ("<toolitem name=\"Back\" "
- "label=\"%s\" "
- "pixtype=\"stock\" pixname=\"gtk-go-back\" "
- "priority=\"1\" "
- "verb=\"GoBack\"/>", _("Back"));;
- break;
- case EPHY_TBI_STD_TOOLITEM_FORWARD:
- xml_item = g_strdup_printf
- ("<toolitem name=\"Forward\" "
- "label=\"%s\" "
- "pixtype=\"stock\" pixname=\"gtk-go-forward\" "
- "verb=\"GoForward\"/>", _("Forward"));
- break;
- case EPHY_TBI_STD_TOOLITEM_UP:
- xml_item = g_strdup_printf
- ("<toolitem name=\"Up\" "
- "label=\"%s\" "
- "pixtype=\"stock\" pixname=\"gtk-go-up\" "
- "verb=\"GoUp\"/>", _("Up"));;
- break;
case EPHY_TBI_STD_TOOLITEM_STOP:
xml_item = g_strdup_printf
("<toolitem name=\"Stop\" "
@@ -388,7 +333,14 @@ ephy_tbi_std_toolitem_add_to_bonobo_tb_impl (EphyTbItem *i, BonoboUIComponent *u
"pixtype=\"stock\" pixname=\"gtk-new\" "
"verb=\"FileNew\"/>", _("New"));;
break;
-
+ case EPHY_TBI_STD_TOOLITEM_ERROR:
+ xml_item = g_strdup_printf
+ ("<toolitem name=\"Error\" "
+ "label=\"%s\" "
+ "pixtype=\"stock\" pixname=\"gtk-cancel\" "
+ "priority=\"1\" "
+ "verb=\"ErrorVerb\"/>", "Erroneous button");
+ break;
default:
g_assert_not_reached ();
xml_item = g_strdup ("");
@@ -412,19 +364,7 @@ ephy_tbi_std_toolitem_parse_properties_impl (EphyTbItem *it, const gchar *props)
if (item_prop)
{
item_prop += strlen ("item=");
- if (!strncmp (item_prop, "back", 4))
- {
- ephy_tbi_std_toolitem_set_item (a, EPHY_TBI_STD_TOOLITEM_BACK);
- }
- else if (!strncmp (item_prop, "forward", 4))
- {
- ephy_tbi_std_toolitem_set_item (a, EPHY_TBI_STD_TOOLITEM_FORWARD);
- }
- else if (!strncmp (item_prop, "up", 2))
- {
- ephy_tbi_std_toolitem_set_item (a, EPHY_TBI_STD_TOOLITEM_UP);
- }
- else if (!strncmp (item_prop, "stop", 4))
+ if (!strncmp (item_prop, "stop", 4))
{
ephy_tbi_std_toolitem_set_item (a, EPHY_TBI_STD_TOOLITEM_STOP);
}
@@ -444,7 +384,10 @@ ephy_tbi_std_toolitem_parse_properties_impl (EphyTbItem *it, const gchar *props)
{
ephy_tbi_std_toolitem_set_item (a, EPHY_TBI_STD_TOOLITEM_NEW);
}
-
+ else
+ {
+ ephy_tbi_std_toolitem_set_item (a, EPHY_TBI_STD_TOOLITEM_ERROR);
+ }
}
}
@@ -453,10 +396,7 @@ ephy_tbi_std_toolitem_set_item (EphyTbiStdToolitem *a, EphyTbiStdToolitemItem i)
{
EphyTbiStdToolitemPrivate *p = a->priv;
- g_return_if_fail (i == EPHY_TBI_STD_TOOLITEM_UP
- || i == EPHY_TBI_STD_TOOLITEM_BACK
- || i == EPHY_TBI_STD_TOOLITEM_FORWARD
- || i == EPHY_TBI_STD_TOOLITEM_STOP
+ g_return_if_fail (i == EPHY_TBI_STD_TOOLITEM_STOP
|| i == EPHY_TBI_STD_TOOLITEM_RELOAD
|| i == EPHY_TBI_STD_TOOLITEM_GO
|| i == EPHY_TBI_STD_TOOLITEM_HOME
diff --git a/lib/toolbar/ephy-tbi-std-toolitem.h b/lib/toolbar/ephy-tbi-std-toolitem.h
index 67073041f..c47d5d7ea 100644
--- a/lib/toolbar/ephy-tbi-std-toolitem.h
+++ b/lib/toolbar/ephy-tbi-std-toolitem.h
@@ -49,14 +49,12 @@ typedef struct _EphyTbiStdToolitemPrivate EphyTbiStdToolitemPrivate;
EphyTbiStdToolitemClass))
typedef enum
{
- EPHY_TBI_STD_TOOLITEM_BACK,
- EPHY_TBI_STD_TOOLITEM_FORWARD,
- EPHY_TBI_STD_TOOLITEM_UP,
EPHY_TBI_STD_TOOLITEM_STOP,
EPHY_TBI_STD_TOOLITEM_RELOAD,
EPHY_TBI_STD_TOOLITEM_HOME,
EPHY_TBI_STD_TOOLITEM_GO,
- EPHY_TBI_STD_TOOLITEM_NEW
+ EPHY_TBI_STD_TOOLITEM_NEW,
+ EPHY_TBI_STD_TOOLITEM_ERROR
} EphyTbiStdToolitemItem;
diff --git a/lib/toolbar/ephy-toolbar-item-factory.c b/lib/toolbar/ephy-toolbar-item-factory.c
index 1637100ae..60cfbbc41 100644
--- a/lib/toolbar/ephy-toolbar-item-factory.c
+++ b/lib/toolbar/ephy-toolbar-item-factory.c
@@ -35,26 +35,42 @@
//#define DEBUG_MSG(x) g_print x
#define DEBUG_MSG(x)
-typedef EphyTbItem *(EphyTbItemConstructor) (void);
-
typedef struct
{
const char *type_name;
- EphyTbItemConstructor *constructor;
+ EphyTbItemConstructor constructor;
} EphyTbItemTypeInfo;
-static EphyTbItemTypeInfo ephy_tb_item_known_types[] =
+static EphyTbItemTypeInfo ephy_tb_item_default_types[] =
{
- { "std_toolitem", (EphyTbItemConstructor *) ephy_tbi_std_toolitem_new },
- { "navigation_history", (EphyTbItemConstructor *) ephy_tbi_navigation_history_new },
- { "zoom", (EphyTbItemConstructor *) ephy_tbi_zoom_new },
- { "location", (EphyTbItemConstructor *) ephy_tbi_location_new },
- { "spinner", (EphyTbItemConstructor *) ephy_tbi_spinner_new },
- { "favicon", (EphyTbItemConstructor *) ephy_tbi_favicon_new },
- { "separator", (EphyTbItemConstructor *) ephy_tbi_separator_new },
+ { "std_toolitem", (EphyTbItemConstructor) ephy_tbi_std_toolitem_new },
+ { "navigation_history", (EphyTbItemConstructor) ephy_tbi_navigation_history_new },
+ { "zoom", (EphyTbItemConstructor) ephy_tbi_zoom_new },
+ { "location", (EphyTbItemConstructor) ephy_tbi_location_new },
+ { "spinner", (EphyTbItemConstructor) ephy_tbi_spinner_new },
+ { "favicon", (EphyTbItemConstructor) ephy_tbi_favicon_new },
+ { "separator", (EphyTbItemConstructor) ephy_tbi_separator_new },
{ NULL, NULL }
};
+static GHashTable *ephy_tb_item_known_types = NULL;
+
+static void
+ephy_tb_item_factory_init (void)
+{
+ if (ephy_tb_item_known_types == NULL)
+ {
+ int i;
+ ephy_tb_item_known_types = g_hash_table_new (g_str_hash, g_str_equal);
+
+ for (i = 0; ephy_tb_item_default_types[i].type_name; ++i)
+ {
+ ephy_toolbar_item_register_type (ephy_tb_item_default_types[i].type_name,
+ ephy_tb_item_default_types[i].constructor);
+ }
+ }
+}
+
EphyTbItem *
ephy_toolbar_item_create_from_string (const gchar *str)
{
@@ -66,7 +82,9 @@ ephy_toolbar_item_create_from_string (const gchar *str)
const gchar *lpar;
const gchar *rpar;
const gchar *eq;
- int i;
+ EphyTbItemConstructor constructor;
+
+ ephy_tb_item_factory_init ();
rest = str;
@@ -104,21 +122,20 @@ ephy_toolbar_item_create_from_string (const gchar *str)
props = NULL;
}
- DEBUG_MSG (("ephytoolbar_item_create_from_string id=%s type=%s props=%s\n", id, type, props));
+ DEBUG_MSG (("ephy_toolbar_item_create_from_string id=%s type=%s props=%s\n", id, type, props));
+
+ constructor = g_hash_table_lookup (ephy_tb_item_known_types, type);
- for (i = 0; ephy_tb_item_known_types[i].type_name; ++i)
+ if (constructor)
{
- if (!strcmp (type, ephy_tb_item_known_types[i].type_name))
+ ret = constructor ();
+ if (id)
+ {
+ ephy_tb_item_set_id (ret, id);
+ }
+ if (props)
{
- ret = ephy_tb_item_known_types[i].constructor ();
- if (id)
- {
- ephy_tb_item_set_id (ret, id);
- }
- if (props)
- {
- ephy_tb_item_parse_properties (ret, props);
- }
+ ephy_tb_item_parse_properties (ret, props);
}
}
@@ -143,16 +160,9 @@ ephy_toolbar_item_create_from_string (const gchar *str)
return ret;
}
-GSList *
-ephy_toolbar_list_item_types (void)
+void
+ephy_toolbar_item_register_type (const gchar *type, EphyTbItemConstructor constructor)
{
- int i;
- GSList *ret = NULL;
- for (i = 0; ephy_tb_item_known_types[i].type_name; ++i)
- {
- ret = g_slist_prepend (ret,
- (gchar *) ephy_tb_item_known_types[i].type_name);
- }
- return ret;
+ ephy_tb_item_factory_init ();
+ g_hash_table_insert (ephy_tb_item_known_types, g_strdup (type), constructor);
}
-
diff --git a/lib/toolbar/ephy-toolbar-item-factory.h b/lib/toolbar/ephy-toolbar-item-factory.h
index e86179399..d613abeeb 100644
--- a/lib/toolbar/ephy-toolbar-item-factory.h
+++ b/lib/toolbar/ephy-toolbar-item-factory.h
@@ -23,8 +23,10 @@
G_BEGIN_DECLS
+typedef EphyTbItem *(*EphyTbItemConstructor) (void);
+
EphyTbItem * ephy_toolbar_item_create_from_string (const gchar *str);
-GSList * ephy_toolbar_list_item_types (void);
+void ephy_toolbar_item_register_type (const gchar *type, EphyTbItemConstructor constructor);
G_END_DECLS