diff options
author | Marco Pesenti Gritti <marco@it.gnome.org> | 2003-04-30 00:47:21 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <mpeseng@src.gnome.org> | 2003-04-30 00:47:21 +0800 |
commit | c46158a00cd6572504ded30c8a9d1ec1b468d07f (patch) | |
tree | 29aa716204dcd4db73bc2e4f9d433b9f00b8efa9 | |
parent | 48b245e9205fc5a9a4745e8e0a3146d32a21f816 (diff) | |
download | gsoc2013-epiphany-c46158a00cd6572504ded30c8a9d1ec1b468d07f.tar gsoc2013-epiphany-c46158a00cd6572504ded30c8a9d1ec1b468d07f.tar.gz gsoc2013-epiphany-c46158a00cd6572504ded30c8a9d1ec1b468d07f.tar.bz2 gsoc2013-epiphany-c46158a00cd6572504ded30c8a9d1ec1b468d07f.tar.lz gsoc2013-epiphany-c46158a00cd6572504ded30c8a9d1ec1b468d07f.tar.xz gsoc2013-epiphany-c46158a00cd6572504ded30c8a9d1ec1b468d07f.tar.zst gsoc2013-epiphany-c46158a00cd6572504ded30c8a9d1ec1b468d07f.zip |
Update
2003-04-29 Marco Pesenti Gritti <marco@it.gnome.org>
* lib/egg/egg-editable-toolbar.c:
* lib/egg/eggtoggletoolbutton.c:
* lib/egg/eggtoolbar.c:
* lib/egg/eggtoolbutton.c:
* lib/egg/eggtoolbutton.h:
Update
-rw-r--r-- | ChangeLog | 10 | ||||
-rwxr-xr-x | lib/egg/egg-editable-toolbar.c | 19 | ||||
-rw-r--r-- | lib/egg/eggtoggletoolbutton.c | 6 | ||||
-rw-r--r-- | lib/egg/eggtoolbar.c | 58 | ||||
-rw-r--r-- | lib/egg/eggtoolbutton.c | 648 | ||||
-rw-r--r-- | lib/egg/eggtoolbutton.h | 17 |
6 files changed, 427 insertions, 331 deletions
@@ -1,5 +1,15 @@ 2003-04-29 Marco Pesenti Gritti <marco@it.gnome.org> + * lib/egg/egg-editable-toolbar.c: + * lib/egg/eggtoggletoolbutton.c: + * lib/egg/eggtoolbar.c: + * lib/egg/eggtoolbutton.c: + * lib/egg/eggtoolbutton.h: + + Update + +2003-04-29 Marco Pesenti Gritti <marco@it.gnome.org> + * lib/egg/egg-editable-toolbar.c: (create_toolbar): Update diff --git a/lib/egg/egg-editable-toolbar.c b/lib/egg/egg-editable-toolbar.c index d070c560a..92d3a3834 100755 --- a/lib/egg/egg-editable-toolbar.c +++ b/lib/egg/egg-editable-toolbar.c @@ -291,6 +291,7 @@ create_toolbar (EggEditableToolbar *t) toolbar = egg_toolbar_new (); egg_toolbar_set_show_arrow (EGG_TOOLBAR (toolbar), TRUE); + gtk_widget_set_sensitive (toolbar, TRUE); gtk_widget_show (toolbar); gtk_drag_dest_set (toolbar, GTK_DEST_DEFAULT_DROP, dest_drag_types, n_dest_drag_types, @@ -602,9 +603,27 @@ egg_editable_toolbar_set_edit_mode (EggEditableToolbar *etoolbar, for (l = 0; l < n_items; l++) { EggToolItem *item; + const char *action_name; + gboolean is_separator; + + action_name = egg_toolbars_model_item_nth + (etoolbar->priv->model, i, l, + &is_separator); item = egg_toolbar_get_nth_item (EGG_TOOLBAR (toolbar), l); egg_tool_item_set_use_drag_window (item, mode); + + if (mode) + { + gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE); + } + else if (!is_separator) + { + EggAction *action; + + action = find_action (etoolbar, action_name); + g_object_notify (G_OBJECT (action), "sensitive"); + } } } } diff --git a/lib/egg/eggtoggletoolbutton.c b/lib/egg/eggtoggletoolbutton.c index 80372a8db..5f489bcec 100644 --- a/lib/egg/eggtoggletoolbutton.c +++ b/lib/egg/eggtoggletoolbutton.c @@ -124,9 +124,9 @@ static GtkWidget * egg_toggle_tool_button_create_menu_proxy (EggToolItem *item) { EggToggleToolButton *button = EGG_TOGGLE_TOOL_BUTTON (item); - const char *label; + gchar *label; - label = gtk_label_get_text (GTK_LABEL (EGG_TOOL_BUTTON (button)->label)); + label = _egg_tool_button_get_label_text (EGG_TOOL_BUTTON (item)); if (button->menu_item) g_object_remove_weak_pointer (G_OBJECT (button->menu_item), @@ -142,6 +142,8 @@ egg_toggle_tool_button_create_menu_proxy (EggToolItem *item) g_object_add_weak_pointer (G_OBJECT (button->menu_item), (gpointer *)&(button->menu_item)); + g_free (label); + return button->menu_item; } diff --git a/lib/egg/eggtoolbar.c b/lib/egg/eggtoolbar.c index d24f5f81b..f109a4988 100644 --- a/lib/egg/eggtoolbar.c +++ b/lib/egg/eggtoolbar.c @@ -36,6 +36,9 @@ #include <gdk/gdkkeysyms.h> #include "eggmarshalers.h" #include <gtk/gtkmain.h> +#include <gtk/gtkstock.h> +#include <gtk/gtklabel.h> +#include <string.h> #define DEFAULT_IPADDING 1 #define DEFAULT_SPACE_SIZE 5 @@ -922,7 +925,7 @@ egg_toolbar_size_allocate (GtkWidget *widget, GtkAllocation *allocation) gint i; gboolean need_arrow; gint n_expand_items; - gint border_width; + gint border_width, internal_padding; gint available_size; gint n_items; gint needed_size; @@ -932,9 +935,8 @@ egg_toolbar_size_allocate (GtkWidget *widget, GtkAllocation *allocation) widget->allocation = *allocation; space_size = get_space_size (toolbar); - - gtk_widget_style_get (widget, "internal_padding", &border_width, NULL); - border_width += GTK_CONTAINER (toolbar)->border_width; + + border_width = GTK_CONTAINER (toolbar)->border_width; if (GTK_WIDGET_REALIZED (widget)) { @@ -945,6 +947,9 @@ egg_toolbar_size_allocate (GtkWidget *widget, GtkAllocation *allocation) allocation->height - border_width * 2); } + gtk_widget_style_get (widget, "internal_padding", &internal_padding, NULL); + border_width += internal_padding; + gtk_widget_get_child_requisition (GTK_WIDGET (priv->arrow_button), &arrow_requisition); @@ -2460,6 +2465,32 @@ egg_toolbar_insert_element (EggToolbar *toolbar, icon, callback, user_data, position, FALSE); } +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 GtkWidget * egg_toolbar_internal_insert_element (EggToolbar *toolbar, EggToolbarChildType type, @@ -2526,12 +2557,23 @@ egg_toolbar_internal_insert_element (EggToolbar *toolbar, { if (text) { - child->label = EGG_TOOL_BUTTON (item)->label; - if (use_stock) - g_object_set (G_OBJECT (item), "stock_id", text, NULL); + { + GtkStockItem stock_item; + gchar *label_text; + + egg_tool_button_set_stock_id (EGG_TOOL_BUTTON (item), text); + + gtk_stock_lookup (text, &stock_item); + label_text = elide_underscores (stock_item.label); + child->label = GTK_WIDGET (gtk_label_new (label_text)); + g_free (label_text); + } else - egg_tool_button_set_label (EGG_TOOL_BUTTON (item), text); + { + child->label = gtk_label_new (text); + } + egg_tool_button_set_label_widget (EGG_TOOL_BUTTON (item), child->label); } if (icon) diff --git a/lib/egg/eggtoolbutton.c b/lib/egg/eggtoolbutton.c index cdbff6e3e..14a83f3b8 100644 --- a/lib/egg/eggtoolbutton.c +++ b/lib/egg/eggtoolbutton.c @@ -44,6 +44,7 @@ enum { PROP_0, PROP_LABEL, PROP_USE_UNDERLINE, + PROP_LABEL_WIDGET, PROP_STOCK_ID, PROP_ICON_SET, PROP_ICON_WIDGET, @@ -63,15 +64,14 @@ static void egg_tool_button_get_property (GObject *object, GValue *value, GParamSpec *pspec); static void egg_tool_button_finalize (GObject *object); -static void egg_tool_button_toolbar_reconfigured (EggToolItem *tool_item); static void egg_tool_button_parent_set (GtkWidget *widget, GtkWidget *parent); -static void egg_tool_button_show_all (GtkWidget *widget); - static GtkWidget *egg_tool_button_create_menu_proxy (EggToolItem *item); static void button_clicked (GtkWidget *widget, EggToolButton *button); +static void egg_tool_button_construct_contents (EggToolItem *tool_item); + static GObjectClass *parent_class = NULL; static guint toolbutton_signals[LAST_SIGNAL] = { 0 }; @@ -119,11 +119,10 @@ egg_tool_button_class_init (EggToolButtonClass *klass) object_class->get_property = egg_tool_button_get_property; object_class->finalize = egg_tool_button_finalize; - widget_class->show_all = egg_tool_button_show_all; widget_class->parent_set = egg_tool_button_parent_set; tool_item_class->create_menu_proxy = egg_tool_button_create_menu_proxy; - tool_item_class->toolbar_reconfigured = egg_tool_button_toolbar_reconfigured; + tool_item_class->toolbar_reconfigured = egg_tool_button_construct_contents; klass->button_type = GTK_TYPE_BUTTON; @@ -138,28 +137,35 @@ egg_tool_button_class_init (EggToolButtonClass *klass) PROP_USE_UNDERLINE, g_param_spec_boolean ("use_underline", _("Use underline"), - _("Interpret underlines in the item label."), + _("Interpret underlines in the item label"), FALSE, G_PARAM_READWRITE)); g_object_class_install_property (object_class, + PROP_LABEL_WIDGET, + g_param_spec_object ("label_widget", + _("Label widget"), + _("Widget to use as the item label"), + GTK_TYPE_WIDGET, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, PROP_STOCK_ID, g_param_spec_string ("stock_id", _("Stock Id"), - _("The stock icon displayed on the item."), + _("The stock icon displayed on the item"), NULL, G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_ICON_SET, g_param_spec_boxed ("icon_set", _("Icon set"), - _("Icon set to use to draw the item's icon."), + _("Icon set to use to draw the item's icon"), GTK_TYPE_ICON_SET, G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_ICON_WIDGET, g_param_spec_object ("icon_widget", _("Icon widget"), - _("Icon widget to display in the item."), + _("Icon widget to display in the item"), GTK_TYPE_WIDGET, G_PARAM_READWRITE)); @@ -186,53 +192,144 @@ egg_tool_button_init (EggToolButton *button, EggToolButtonClass *klass) /* FIXME: enable this when we can depend on gtk+ 2.3.0 */ gtk_button_set_focus_on_click (button->button, FALSE); #endif - g_signal_connect_object (button->button, "clicked", G_CALLBACK (button_clicked), button, 0); - button->box = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (button->button), button->box); - gtk_widget_show (button->box); - -#if 0 - button->icon = gtk_image_new(); - gtk_box_pack_start (GTK_BOX (button->box), button->icon, TRUE, TRUE, 0); - gtk_widget_show (button->icon); -#endif - - button->label = gtk_label_new (NULL); - gtk_label_set_use_underline (GTK_LABEL (button->label), TRUE); - gtk_box_pack_start (GTK_BOX (button->box), button->label, FALSE, TRUE, 0); - gtk_widget_show (button->label); - gtk_container_add (GTK_CONTAINER (button), button->button); gtk_widget_show (button->button); } -static gchar * -elide_underscores (const gchar *original) +static void +egg_tool_button_construct_contents (EggToolItem *tool_item) { - gchar *q, *result; - const gchar *p; - gboolean last_underscore; + EggToolButton *button = EGG_TOOL_BUTTON (tool_item); + GtkWidget *label = NULL; + GtkWidget *icon = NULL; + GtkToolbarStyle style; + gboolean need_label = FALSE; + gboolean need_icon = FALSE; + GtkIconSize icon_size; + GtkWidget *box = NULL; + + if (button->icon_widget && button->icon_widget->parent) + { + gtk_container_remove (GTK_CONTAINER (button->icon_widget->parent), + button->icon_widget); + } - q = result = g_malloc (strlen (original) + 1); - last_underscore = FALSE; + if (button->label_widget && button->label_widget->parent) + { + gtk_container_remove (GTK_CONTAINER (button->label_widget->parent), + button->label_widget); + } + + if (GTK_BIN (button->button)->child) + { + gtk_container_remove (GTK_CONTAINER (button->button), + GTK_BIN (button->button)->child); + } + + style = egg_tool_item_get_toolbar_style (EGG_TOOL_ITEM (button)); - for (p = original; *p; p++) + if (style != GTK_TOOLBAR_TEXT) + need_icon = TRUE; + + if (style != GTK_TOOLBAR_ICONS) + need_label = TRUE; + + if (need_label) { - if (!last_underscore && *p == '_') - last_underscore = TRUE; + if (button->label_widget) + { + label = button->label_widget; + } else { - last_underscore = FALSE; - *q++ = *p; + gchar *text = _egg_tool_button_get_label_text (button); + label = gtk_label_new (text); + g_free (text); } } - - *q = '\0'; - - return result; + + icon_size = egg_tool_item_get_icon_size (EGG_TOOL_ITEM (button)); + if (need_icon) + { + if (button->icon_set) + { + icon = gtk_image_new_from_icon_set (button->icon_set, icon_size); + gtk_widget_show (icon); + } + else if (button->icon_widget) + { + if (GTK_IS_IMAGE (button->icon_widget)) + { + GtkImage *image = GTK_IMAGE (button->icon_widget); + 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. + */ + + if (storage_type == GTK_IMAGE_STOCK) + { + gchar *stock_id; + gtk_image_get_stock (image, &stock_id, NULL); + gtk_image_set_from_stock (image, stock_id, icon_size); + } + else if (storage_type == GTK_IMAGE_ICON_SET) + { + GtkIconSet *icon_set; + gtk_image_get_icon_set (image, &icon_set, NULL); + gtk_image_set_from_icon_set (image, icon_set, icon_size); + } + } + + icon = button->icon_widget; + } + else if (button->stock_id) + { + icon = gtk_image_new_from_stock (button->stock_id, icon_size); + gtk_widget_show (icon); + } + } + + switch (style) + { + case GTK_TOOLBAR_ICONS: + if (icon) + gtk_container_add (GTK_CONTAINER (button->button), icon); + break; + + case GTK_TOOLBAR_BOTH: + box = gtk_vbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (box), icon, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (box), label, FALSE, TRUE, 0); + gtk_container_add (GTK_CONTAINER (button->button), box); + break; + + case GTK_TOOLBAR_BOTH_HORIZ: + box = gtk_hbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (box), icon, FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0); + gtk_container_add (GTK_CONTAINER (button->button), box); + break; + + case GTK_TOOLBAR_TEXT: + gtk_container_add (GTK_CONTAINER (button->button), label); + break; + } + + if (label) + gtk_widget_show (label); + if (icon) + gtk_widget_show (icon); + if (box) + gtk_widget_show (box); + + gtk_button_set_relief (GTK_BUTTON (button->button), + egg_tool_item_get_relief_style (EGG_TOOL_ITEM (button))); + + gtk_widget_queue_resize (GTK_WIDGET (button)); } static void @@ -251,6 +348,9 @@ egg_tool_button_set_property (GObject *object, case PROP_USE_UNDERLINE: egg_tool_button_set_use_underline (button, g_value_get_boolean (value)); break; + case PROP_LABEL_WIDGET: + egg_tool_button_set_label_widget (button, g_value_get_object (value)); + break; case PROP_STOCK_ID: egg_tool_button_set_stock_id (button, g_value_get_string (value)); break; @@ -278,9 +378,11 @@ egg_tool_button_get_property (GObject *object, case PROP_LABEL: g_value_set_string (value, egg_tool_button_get_label (button)); break; + case PROP_LABEL_WIDGET: + g_value_set_object (value, egg_tool_button_get_label_widget (button)); + break; case PROP_USE_UNDERLINE: - g_value_set_boolean (value, - gtk_label_get_use_underline (GTK_LABEL (button->label))); + g_value_set_boolean (value, egg_tool_button_get_use_underline (button)); break; case PROP_STOCK_ID: g_value_set_string (value, button->stock_id); @@ -289,7 +391,7 @@ egg_tool_button_get_property (GObject *object, g_value_set_boxed (value, egg_tool_button_get_icon_set (button)); break; case PROP_ICON_WIDGET: - g_value_set_object (value, button->icon); + g_value_set_object (value, button->icon_widget); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -307,199 +409,60 @@ egg_tool_button_finalize (GObject *object) parent_class->finalize (object); } -static void -egg_tool_button_show_all (GtkWidget *widget) -{ - EggToolButton *button = EGG_TOOL_BUTTON (widget); - GtkToolbarStyle style = egg_tool_item_get_toolbar_style (EGG_TOOL_ITEM (button)); - - switch (style) - { - case GTK_TOOLBAR_ICONS: - if (button->icon) gtk_widget_show_all (button->icon); - gtk_widget_hide (button->label); - gtk_widget_show (button->box); - gtk_widget_show (button->button); - break; - case GTK_TOOLBAR_TEXT: - if (button->icon) gtk_widget_hide (button->icon); - gtk_widget_show_all (button->label); - gtk_widget_show (button->box); - gtk_widget_show (button->button); - break; - case GTK_TOOLBAR_BOTH: - case GTK_TOOLBAR_BOTH_HORIZ: - gtk_widget_show_all (button->button); - } - - gtk_widget_show (GTK_WIDGET (button)); -} - static GtkWidget * egg_tool_button_create_menu_proxy (EggToolItem *item) { EggToolButton *button = EGG_TOOL_BUTTON (item); GtkWidget *menu_item; - GtkWidget *image; - const char *label; - - label = gtk_label_get_text (GTK_LABEL (button->label)); + 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); - if (GTK_IS_IMAGE (button->icon)) + if (button->icon_set) { - image = gtk_image_new (); - - if (GTK_IMAGE (button->icon)->storage_type == GTK_IMAGE_STOCK) - { - gchar *stock_id; - - gtk_image_get_stock (GTK_IMAGE (button->icon), - &stock_id, NULL); - gtk_image_set_from_stock (GTK_IMAGE (image), stock_id, - GTK_ICON_SIZE_MENU); - } - else if (GTK_IMAGE (button->icon)->storage_type == GTK_IMAGE_ICON_SET) - { - GtkIconSet *icon_set; - - gtk_image_get_icon_set (GTK_IMAGE (button->icon), &icon_set, NULL); - gtk_image_set_from_icon_set (GTK_IMAGE (image), icon_set, - GTK_ICON_SIZE_MENU); - } - else - { - g_warning ("FIXME: Add more cases here"); - } - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image); + menu_image = gtk_image_new_from_icon_set (button->icon_set, GTK_ICON_SIZE_MENU); } - - g_signal_connect_object (menu_item, "activate", - G_CALLBACK (gtk_button_clicked), - EGG_TOOL_BUTTON (button)->button, - G_CONNECT_SWAPPED); - - return menu_item; -} - -static void -use_new_box (EggToolButton *tool_button, GtkWidget *new_box) -{ - if (tool_button->icon) - gtk_widget_reparent (tool_button->icon, new_box); - - gtk_widget_reparent (tool_button->label, new_box); - - gtk_container_remove (GTK_CONTAINER (tool_button->button), tool_button->box); - tool_button->box = new_box; - gtk_container_add (GTK_CONTAINER (tool_button->button), new_box); -} - -static void -show_both (EggToolButton *tool_button) -{ - gtk_widget_show (tool_button->label); - if (tool_button->icon) - gtk_widget_show (tool_button->icon); -} - -static void -egg_tool_button_toolbar_reconfigured (EggToolItem *tool_item) -{ - EggToolButton *tool_button = EGG_TOOL_BUTTON (tool_item); - - /* icon size */ - if (tool_button->icon && GTK_IS_IMAGE (tool_button->icon)) + else if (button->icon_widget && GTK_IS_IMAGE (button->icon_widget)) { - GtkImage *image = GTK_IMAGE (tool_button->icon); - GtkImageType storage = gtk_image_get_storage_type (image); - GtkIconSize new_icon_size = egg_tool_item_get_icon_size (EGG_TOOL_ITEM (tool_button)); - - if (storage == GTK_IMAGE_STOCK) + GtkImage *image = GTK_IMAGE (button->icon_widget); + GtkImageType storage_type = gtk_image_get_storage_type (image); + + if (storage_type == GTK_IMAGE_STOCK) { gchar *stock_id; gtk_image_get_stock (image, &stock_id, NULL); - gtk_image_set_from_stock (image, stock_id, new_icon_size); + menu_image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU); } - else if (storage == GTK_IMAGE_ICON_SET) + else if (storage_type == GTK_IMAGE_ICON_SET) { GtkIconSet *icon_set; gtk_image_get_icon_set (image, &icon_set, NULL); - gtk_image_set_from_icon_set (image, icon_set, new_icon_size); + menu_image = gtk_image_new_from_icon_set (icon_set, GTK_ICON_SIZE_MENU); } } - - /* toolbar style */ - switch (egg_tool_item_get_toolbar_style (EGG_TOOL_ITEM (tool_button))) + else if (button->stock_id) { - case GTK_TOOLBAR_ICONS: - gtk_widget_hide (tool_button->label); - if (tool_button->icon) - { - gtk_box_set_child_packing (GTK_BOX (tool_button->box), tool_button->icon, - TRUE, TRUE, 0, GTK_PACK_START); - gtk_widget_show (tool_button->icon); - } - break; - - case GTK_TOOLBAR_TEXT: - gtk_box_set_child_packing (GTK_BOX (tool_button->box), tool_button->label, - TRUE, TRUE, 0, GTK_PACK_START); - gtk_widget_show (tool_button->label); - if (tool_button->icon) - gtk_widget_hide (tool_button->icon); - break; - - case GTK_TOOLBAR_BOTH: - if (GTK_IS_HBOX (tool_button->box)) - { - GtkWidget *vbox = gtk_vbox_new (FALSE, 0); - gtk_widget_show (vbox); - - use_new_box (tool_button, vbox); - } - show_both (tool_button); - - gtk_box_set_child_packing (GTK_BOX (tool_button->box), tool_button->label, - FALSE, TRUE, 0, GTK_PACK_START); - if (tool_button->icon) - gtk_box_set_child_packing (GTK_BOX (tool_button->box), tool_button->icon, - TRUE, TRUE, 0, GTK_PACK_START); - break; - - case GTK_TOOLBAR_BOTH_HORIZ: - if (GTK_IS_VBOX (tool_button->box)) - { - GtkWidget *hbox = gtk_hbox_new (FALSE, 0); - gtk_widget_show (hbox); - - use_new_box (tool_button, hbox); - } - - show_both (tool_button); - - gtk_box_set_child_packing (GTK_BOX (tool_button->box), tool_button->label, - TRUE, TRUE, 0, GTK_PACK_START); - if (tool_button->icon) - gtk_box_set_child_packing (GTK_BOX (tool_button->box), tool_button->icon, - FALSE, TRUE, 0, GTK_PACK_START); - - break; + menu_image = gtk_image_new_from_stock (button->stock_id, GTK_ICON_SIZE_MENU); } - /* relief style */ - gtk_button_set_relief (GTK_BUTTON (tool_button->button), - egg_tool_item_get_relief_style (EGG_TOOL_ITEM (tool_button))); + if (menu_image) + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), menu_image); - - gtk_widget_queue_resize (GTK_WIDGET (tool_button)); + g_signal_connect_object (menu_item, "activate", + G_CALLBACK (gtk_button_clicked), + EGG_TOOL_BUTTON (button)->button, + G_CONNECT_SWAPPED); + + return menu_item; } static void egg_tool_button_parent_set (GtkWidget *widget, GtkWidget *parent) { - egg_tool_button_toolbar_reconfigured (EGG_TOOL_ITEM (widget)); + egg_tool_button_construct_contents (EGG_TOOL_ITEM (widget)); } static void @@ -517,7 +480,6 @@ egg_tool_button_new_from_stock (const gchar *stock_id) button = g_object_new (EGG_TYPE_TOOL_BUTTON, "stock_id", stock_id, - "use_underline", TRUE, NULL); return EGG_TOOL_ITEM (button); @@ -534,72 +496,31 @@ egg_tool_button_new (void) return EGG_TOOL_ITEM (button); } -GtkWidget * -egg_tool_button_get_icon_widget (EggToolButton *button) -{ - g_return_val_if_fail (GTK_IS_BUTTON (button), NULL); - - return button->icon; -} - -void -egg_tool_button_set_icon_widget (EggToolButton *button, - GtkWidget *icon) -{ - g_return_if_fail (EGG_IS_TOOL_BUTTON (button)); - g_return_if_fail (icon == NULL || GTK_IS_WIDGET (icon)); - - if (button->icon) - gtk_container_remove (GTK_CONTAINER (button->box), button->icon); - button->icon = NULL; - - button->icon_set = (icon != NULL); - if (icon) - { - button->icon = icon; - gtk_box_pack_start (GTK_BOX (button->box), button->icon, - TRUE, TRUE, 0); - gtk_box_reorder_child (GTK_BOX (button->box), button->icon, 0); - } - else if (button->stock_id) - { - button->icon = gtk_image_new_from_stock (button->stock_id, - egg_tool_item_get_icon_size (EGG_TOOL_ITEM (button))); - gtk_box_pack_start (GTK_BOX (button->box), button->icon, - TRUE, TRUE, 0); - } -} - void egg_tool_button_set_label (EggToolButton *button, const gchar *label) { - gchar *label_no_mnemonic = NULL; - GtkStockItem stock_item; - g_return_if_fail (EGG_IS_TOOL_BUTTON (button)); - button->label_set = (label != NULL); + if (label != button->label_text) + { + if (button->label_text) + g_free (button->label_text); + + button->label_text = g_strdup (label); + + egg_tool_button_construct_contents (EGG_TOOL_ITEM (button)); - if (label) - label_no_mnemonic = elide_underscores (label); - else if (button->stock_id && gtk_stock_lookup (button->stock_id, &stock_item)) - label_no_mnemonic = elide_underscores (stock_item.label); - - gtk_label_set_label (GTK_LABEL (button->label), label_no_mnemonic); - g_free (label_no_mnemonic); + g_object_notify (G_OBJECT (button), "label"); + } } G_CONST_RETURN gchar * egg_tool_button_get_label (EggToolButton *button) { g_return_val_if_fail (EGG_IS_TOOL_BUTTON (button), NULL); - - if (button->label_set) - return gtk_label_get_label (GTK_LABEL (button->label)); - /* FIXME: is it right to return NULL here? */ - return NULL; + return button->label_text; } void @@ -608,7 +529,16 @@ egg_tool_button_set_use_underline (EggToolButton *button, { g_return_if_fail (EGG_IS_TOOL_BUTTON (button)); - gtk_label_set_use_underline (GTK_LABEL (button->label), use_underline); + use_underline = use_underline != FALSE; + + if (use_underline != button->use_underline) + { + button->use_underline = use_underline; + + egg_tool_button_construct_contents (EGG_TOOL_ITEM (button)); + + g_object_notify (G_OBJECT (button), "use_underline"); + } } gboolean @@ -616,7 +546,7 @@ egg_tool_button_get_use_underline (EggToolButton *button) { g_return_val_if_fail (EGG_IS_TOOL_BUTTON (button), FALSE); - return gtk_label_get_use_underline (GTK_LABEL (button->label)); + return button->use_underline; } void @@ -624,40 +554,17 @@ egg_tool_button_set_stock_id (EggToolButton *button, const gchar *stock_id) { g_return_if_fail (EGG_IS_TOOL_BUTTON (button)); - g_return_if_fail (stock_id != NULL); - g_free (button->stock_id); - button->stock_id = g_strdup (stock_id); - if (!button->label_set) + if (button->stock_id != stock_id) { - GtkStockItem stock_item; - gchar *label_no_mnemonic; + if (button->stock_id) + g_free (button->stock_id); + + button->stock_id = g_strdup (stock_id); - if (gtk_stock_lookup (button->stock_id, &stock_item)) - { - label_no_mnemonic = elide_underscores (stock_item.label); - gtk_label_set_label (GTK_LABEL (button->label), label_no_mnemonic); - g_free (label_no_mnemonic); - } - } - if (!button->icon_set) - { - if (button->icon && !GTK_IS_IMAGE (button->icon)) - { - gtk_container_remove (GTK_CONTAINER (button->box), button->icon); - button->icon = NULL; - } - if (!button->icon) - { - button->icon = gtk_image_new (); - gtk_box_pack_start (GTK_BOX (button->box), button->icon, - TRUE, TRUE, 0); - gtk_box_reorder_child (GTK_BOX (button->box), button->icon, 0); - } - gtk_image_set_from_stock (GTK_IMAGE (button->icon), button->stock_id, - egg_tool_item_get_icon_size (EGG_TOOL_ITEM (button))); - if (egg_tool_item_get_toolbar_style (EGG_TOOL_ITEM (button)) != GTK_TOOLBAR_TEXT) - gtk_widget_show (button->icon); + egg_tool_button_construct_contents (EGG_TOOL_ITEM (button)); + + g_object_notify (G_OBJECT (button), "stock_id"); } } @@ -669,18 +576,72 @@ egg_tool_button_get_stock_id (EggToolButton *button) return button->stock_id; } -GtkIconSet * -egg_tool_button_get_icon_set (EggToolButton *button) +void +egg_tool_button_set_icon_widget (EggToolButton *button, + GtkWidget *icon) { - GtkIconSet *icon_set = NULL; - - if (GTK_IS_IMAGE (button->icon) && - GTK_IMAGE (button->icon)->storage_type == GTK_IMAGE_ICON_SET) + g_return_if_fail (EGG_IS_TOOL_BUTTON (button)); + g_return_if_fail (icon == NULL || GTK_IS_WIDGET (icon)); + + if (icon != button->icon_widget) + { + g_object_freeze_notify (G_OBJECT (button)); + + if (button->icon_widget) + g_object_unref (G_OBJECT (button->icon_widget)); + + if (icon) + button->icon_widget = g_object_ref (icon); + + if (button->icon_widget && button->icon_set) + { + gtk_icon_set_unref (button->icon_set); + button->icon_set = NULL; + + g_object_notify (G_OBJECT (button), "icon_set"); + } + + egg_tool_button_construct_contents (EGG_TOOL_ITEM (button)); + + g_object_notify (G_OBJECT (button), "icon_widget"); + g_object_thaw_notify (G_OBJECT (button)); + } +} + +void +egg_tool_button_set_label_widget (EggToolButton *button, + GtkWidget *label_widget) +{ + g_return_if_fail (EGG_IS_TOOL_BUTTON (button)); + g_return_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget)); + + if (label_widget != button->label_widget) { - gtk_image_get_icon_set (GTK_IMAGE (button->icon), &icon_set, NULL); + if (button->label_widget) + g_object_unref (button->label_widget); + + button->label_widget = g_object_ref (label_widget); + + egg_tool_button_construct_contents (EGG_TOOL_ITEM (button)); + + g_object_notify (G_OBJECT (button), "label_widget"); } +} + +GtkWidget * +egg_tool_button_get_label_widget (EggToolButton *button) +{ + g_return_val_if_fail (EGG_IS_TOOL_BUTTON (button), NULL); - return icon_set; + return button->label_widget; +} + +GtkWidget * +egg_tool_button_get_icon_widget (EggToolButton *button) +{ + g_return_val_if_fail (GTK_IS_BUTTON (button), NULL); + + return button->icon_widget; } void @@ -688,24 +649,79 @@ egg_tool_button_set_icon_set (EggToolButton *button, GtkIconSet *icon_set) { g_return_if_fail (EGG_IS_TOOL_BUTTON (button)); + + if (icon_set != button->icon_set) + { + g_object_freeze_notify (G_OBJECT (button)); + + if (button->icon_set) + gtk_icon_set_unref (button->icon_set); + + button->icon_set = icon_set; + + if (button->icon_set && button->icon_widget) + { + g_object_unref (button->icon_widget); + button->icon_widget = NULL; + + g_object_notify (G_OBJECT (button->icon_widget), "icon_widget"); + } + + egg_tool_button_construct_contents (EGG_TOOL_ITEM (button)); + + g_object_notify (G_OBJECT (button), "icon_set"); + g_object_thaw_notify (G_OBJECT (button)); + } +} + +GtkIconSet * +egg_tool_button_get_icon_set (EggToolButton *button) +{ + g_return_val_if_fail (EGG_IS_TOOL_BUTTON (button), NULL); + + return button->icon_set; +} + +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; - if (button->icon && !GTK_IS_IMAGE (button->icon)) + for (p = original; *p; p++) { - gtk_container_remove (GTK_CONTAINER (button->box), button->icon); - button->icon = NULL; + if (!last_underscore && *p == '_') + last_underscore = TRUE; + else + { + last_underscore = FALSE; + *q++ = *p; + } } - if (!button->icon) + + *q = '\0'; + + return result; +} + +gchar * +_egg_tool_button_get_label_text (EggToolButton *button) +{ + GtkStockItem stock_item; + + if (button->label_text) { - button->icon = gtk_image_new (); - gtk_box_pack_start (GTK_BOX (button->box), button->icon, - TRUE, TRUE, 0); - gtk_box_reorder_child (GTK_BOX (button->box), button->icon, 0); + if (button->use_underline) + return elide_underscores (button->label_text); + else + return g_strdup (button->label_text); } - button->icon_set = (icon_set != NULL); - if (!button->icon_set && button->stock_id) - gtk_image_set_from_stock (GTK_IMAGE (button->icon), button->stock_id, - egg_tool_item_get_icon_size (EGG_TOOL_ITEM (button))); + else if (button->stock_id && gtk_stock_lookup (button->stock_id, &stock_item)) + return elide_underscores (stock_item.label); else - gtk_image_set_from_icon_set (GTK_IMAGE (button->icon), icon_set, - egg_tool_item_get_icon_size (EGG_TOOL_ITEM (button))); + return g_strdup (""); } diff --git a/lib/egg/eggtoolbutton.h b/lib/egg/eggtoolbutton.h index 1c2071c54..9fb143116 100644 --- a/lib/egg/eggtoolbutton.h +++ b/lib/egg/eggtoolbutton.h @@ -42,13 +42,14 @@ struct _EggToolButton /*< private >*/ GtkWidget *button; - GtkWidget *box; - GtkWidget *label; - GtkWidget *icon; gchar *stock_id; - guint label_set : 1; - guint icon_set : 1; + gchar *label_text; + GtkWidget *label_widget; + GtkWidget *icon_widget; + GtkIconSet *icon_set; + + guint use_underline : 1; }; struct _EggToolButtonClass @@ -82,6 +83,12 @@ void egg_tool_button_set_icon_widget (EggToolButton *button, GtkWidget *icon); GtkWidget * egg_tool_button_get_icon_widget (EggToolButton *button); +void egg_tool_button_set_label_widget (EggToolButton *button, + GtkWidget *label_widget); +GtkWidget * egg_tool_button_get_label_widget (EggToolButton *button); + +/* internal function */ +gchar * _egg_tool_button_get_label_text (EggToolButton *button); G_END_DECLS |