From 2ef1b5bf42b5d429e00f94710458f237d18315b2 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 24 Aug 2008 13:17:11 +0000 Subject: Progress update: - Get the "New" button and menu working. - Add a GtkMenuToolButton subclass called EMenuToolButton, which does some behind-the-scenes stuff to make the "New" button work properly. - Kill EComboButton and its associated a11y widget. svn path=/branches/kill-bonobo/; revision=36045 --- widgets/misc/e-menu-tool-button.c | 148 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 widgets/misc/e-menu-tool-button.c (limited to 'widgets/misc/e-menu-tool-button.c') diff --git a/widgets/misc/e-menu-tool-button.c b/widgets/misc/e-menu-tool-button.c new file mode 100644 index 0000000000..be77895fbe --- /dev/null +++ b/widgets/misc/e-menu-tool-button.c @@ -0,0 +1,148 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-menu-tool-button.c + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * 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., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "e-menu-tool-button.h" + +static gpointer parent_class; + +static GtkWidget * +menu_tool_button_clone_image (GtkWidget *source) +{ + GtkIconSize size; + GtkImageType image_type; + const gchar *icon_name; + + /* XXX This isn't general purpose because it requires that the + * source image be using a named icon. Somewhat surprised + * GTK+ doesn't offer something like this. */ + image_type = gtk_image_get_storage_type (GTK_IMAGE (source)); + g_return_val_if_fail (image_type == GTK_IMAGE_ICON_NAME, NULL); + gtk_image_get_icon_name (GTK_IMAGE (source), &icon_name, &size); + + return gtk_image_new_from_icon_name (icon_name, size); +} + +static GtkMenuItem * +menu_tool_button_get_first_menu_item (GtkMenuToolButton *menu_tool_button) +{ + GtkWidget *menu; + GList *children; + + menu = gtk_menu_tool_button_get_menu (menu_tool_button); + if (!GTK_IS_MENU (menu)) + return NULL; + + /* XXX GTK+ 2.12 provides no accessor function. */ + children = GTK_MENU_SHELL (menu)->children; + if (children == NULL || children->next == NULL) + return NULL; + + /* Return the /second/ menu item, which turns out to be the first + * visible item. The first menu item is some kind of placeholder? */ + return GTK_MENU_ITEM (children->next->data); +} + +static void +menu_tool_button_update_icon (GtkToolButton *tool_button) +{ + GtkMenuItem *menu_item; + GtkMenuToolButton *menu_tool_button; + GtkImageMenuItem *image_menu_item; + GtkWidget *image; + + menu_tool_button = GTK_MENU_TOOL_BUTTON (tool_button); + menu_item = menu_tool_button_get_first_menu_item (menu_tool_button); + if (!GTK_IS_IMAGE_MENU_ITEM (menu_item)) + return; + + image_menu_item = GTK_IMAGE_MENU_ITEM (menu_item); + image = gtk_image_menu_item_get_image (image_menu_item); + if (!GTK_IS_IMAGE (image)) + return; + + image = menu_tool_button_clone_image (image); + gtk_tool_button_set_icon_widget (tool_button, image); + gtk_widget_show (image); +} + +static void +menu_tool_button_clicked (GtkToolButton *tool_button) +{ + GtkMenuItem *menu_item; + GtkMenuToolButton *menu_tool_button; + + menu_tool_button = GTK_MENU_TOOL_BUTTON (tool_button); + menu_item = menu_tool_button_get_first_menu_item (menu_tool_button); + + if (GTK_IS_MENU_ITEM (menu_item)) + gtk_menu_item_activate (menu_item); +} + +static void +menu_tool_button_class_init (EMenuToolButtonClass *class) +{ + GtkToolButtonClass *tool_button_class; + + parent_class = g_type_class_peek_parent (class); + + tool_button_class = GTK_TOOL_BUTTON_CLASS (class); + tool_button_class->clicked = menu_tool_button_clicked; +} + +static void +menu_tool_button_init (EMenuToolButton *button) +{ + g_signal_connect ( + button, "notify::menu", + G_CALLBACK (menu_tool_button_update_icon), NULL); +} + +GType +e_menu_tool_button_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + const GTypeInfo type_info = { + sizeof (EMenuToolButtonClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) menu_tool_button_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EMenuToolButton), + 0, /* n_preallocs */ + (GInstanceInitFunc) menu_tool_button_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GTK_TYPE_MENU_TOOL_BUTTON, "EMenuToolButton", + &type_info, 0); + } + + return type; +} + +GtkToolItem * +e_menu_tool_button_new (const gchar *label) +{ + return g_object_new (E_TYPE_MENU_TOOL_BUTTON, "label", label, NULL); +} -- cgit v1.2.3 From 8bbf952350c37970e8947b807513e58e91435998 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 31 Aug 2008 12:29:42 +0000 Subject: Fix some bugs related to the New menu and toolbar button. svn path=/branches/kill-bonobo/; revision=36232 --- widgets/misc/e-menu-tool-button.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'widgets/misc/e-menu-tool-button.c') diff --git a/widgets/misc/e-menu-tool-button.c b/widgets/misc/e-menu-tool-button.c index be77895fbe..f2ff6ded44 100644 --- a/widgets/misc/e-menu-tool-button.c +++ b/widgets/misc/e-menu-tool-button.c @@ -51,12 +51,10 @@ menu_tool_button_get_first_menu_item (GtkMenuToolButton *menu_tool_button) /* XXX GTK+ 2.12 provides no accessor function. */ children = GTK_MENU_SHELL (menu)->children; - if (children == NULL || children->next == NULL) + if (children == NULL) return NULL; - /* Return the /second/ menu item, which turns out to be the first - * visible item. The first menu item is some kind of placeholder? */ - return GTK_MENU_ITEM (children->next->data); + return GTK_MENU_ITEM (children->data); } static void -- cgit v1.2.3 From 6b2295c93a40f6010d94399666a8e099aded8e85 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 19 Sep 2008 18:21:06 +0000 Subject: Fix some miscellaneous address book bugs. Kill e-shell-constants.h. svn path=/branches/kill-bonobo/; revision=36392 --- widgets/misc/e-menu-tool-button.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'widgets/misc/e-menu-tool-button.c') diff --git a/widgets/misc/e-menu-tool-button.c b/widgets/misc/e-menu-tool-button.c index f2ff6ded44..70e64d8124 100644 --- a/widgets/misc/e-menu-tool-button.c +++ b/widgets/misc/e-menu-tool-button.c @@ -58,12 +58,14 @@ menu_tool_button_get_first_menu_item (GtkMenuToolButton *menu_tool_button) } static void -menu_tool_button_update_icon (GtkToolButton *tool_button) +menu_tool_button_update_button (GtkToolButton *tool_button) { GtkMenuItem *menu_item; GtkMenuToolButton *menu_tool_button; GtkImageMenuItem *image_menu_item; + GtkAction *action; GtkWidget *image; + gchar *tooltip = NULL; menu_tool_button = GTK_MENU_TOOL_BUTTON (tool_button); menu_item = menu_tool_button_get_first_menu_item (menu_tool_button); @@ -78,6 +80,14 @@ menu_tool_button_update_icon (GtkToolButton *tool_button) image = menu_tool_button_clone_image (image); gtk_tool_button_set_icon_widget (tool_button, image); gtk_widget_show (image); + + /* If the menu item is a proxy for a GtkAction, extract + * the action's tooltip and use it as our own tooltip. */ + action = gtk_widget_get_action (GTK_WIDGET (menu_item)); + if (action != NULL) + g_object_get (action, "tooltip", &tooltip, NULL); + gtk_widget_set_tooltip_text (GTK_WIDGET (tool_button), tooltip); + g_free (tooltip); } static void @@ -109,7 +119,7 @@ menu_tool_button_init (EMenuToolButton *button) { g_signal_connect ( button, "notify::menu", - G_CALLBACK (menu_tool_button_update_icon), NULL); + G_CALLBACK (menu_tool_button_update_button), NULL); } GType -- cgit v1.2.3 From 791c982c456fca453978358d2e919082419b7808 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Wed, 1 Oct 2008 21:51:10 +0000 Subject: Update the headers on files I've created or completely rewritten to match Sankar's LGPLv3 template. svn path=/branches/kill-bonobo/; revision=36535 --- widgets/misc/e-menu-tool-button.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'widgets/misc/e-menu-tool-button.c') diff --git a/widgets/misc/e-menu-tool-button.c b/widgets/misc/e-menu-tool-button.c index 70e64d8124..5e87de8175 100644 --- a/widgets/misc/e-menu-tool-button.c +++ b/widgets/misc/e-menu-tool-button.c @@ -1,21 +1,22 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-menu-tool-button.c - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) +/* + * e-menu-tool-button.c * * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. * * 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. + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) * - * 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., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. */ #include "e-menu-tool-button.h" -- cgit v1.2.3 From 672adf12a0923437e90d08ab7925bd9329fcce0d Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 16 Aug 2009 11:25:08 -0400 Subject: Fix compiler warnings and deprecated GTK+ API usage. --- widgets/misc/e-menu-tool-button.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'widgets/misc/e-menu-tool-button.c') diff --git a/widgets/misc/e-menu-tool-button.c b/widgets/misc/e-menu-tool-button.c index 53778e6678..58c8317053 100644 --- a/widgets/misc/e-menu-tool-button.c +++ b/widgets/misc/e-menu-tool-button.c @@ -84,7 +84,8 @@ menu_tool_button_update_button (GtkToolButton *tool_button) /* If the menu item is a proxy for a GtkAction, extract * the action's tooltip and use it as our own tooltip. */ - action = gtk_widget_get_action (GTK_WIDGET (menu_item)); + action = gtk_activatable_get_related_action ( + GTK_ACTIVATABLE (menu_item)); if (action != NULL) g_object_get (action, "tooltip", &tooltip, NULL); gtk_widget_set_tooltip_text (GTK_WIDGET (tool_button), tooltip); -- cgit v1.2.3 From 452650a573432a6416f3f31ec0594b888a52b93f Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 24 Aug 2009 23:35:46 -0400 Subject: Bug 359909 - "New" Button too small --- widgets/misc/e-menu-tool-button.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'widgets/misc/e-menu-tool-button.c') diff --git a/widgets/misc/e-menu-tool-button.c b/widgets/misc/e-menu-tool-button.c index 58c8317053..fcf73d6c4e 100644 --- a/widgets/misc/e-menu-tool-button.c +++ b/widgets/misc/e-menu-tool-button.c @@ -92,6 +92,27 @@ menu_tool_button_update_button (GtkToolButton *tool_button) g_free (tooltip); } +static void +menu_tool_button_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + gint minimum_width; + + /* Chain up to parent's size_request() method. */ + GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition); + + /* XXX This is a hack. This widget is only used for the New + * button in the main window toolbar. The New button is + * pretty important, but the word "New" is pretty short + * (in English, anyway) and this results in a small screen + * target when using a "text below item" toolbar style. + * + * We can't go hard-coding a width, but we -can- use a + * heuristic based on the toolbar button height. */ + minimum_width = requisition->height * 2; + requisition->width = MAX (minimum_width, requisition->width); +} + static void menu_tool_button_clicked (GtkToolButton *tool_button) { @@ -108,10 +129,14 @@ menu_tool_button_clicked (GtkToolButton *tool_button) static void menu_tool_button_class_init (EMenuToolButtonClass *class) { + GtkWidgetClass *widget_class; GtkToolButtonClass *tool_button_class; parent_class = g_type_class_peek_parent (class); + widget_class = GTK_WIDGET_CLASS (class); + widget_class->size_request = menu_tool_button_size_request; + tool_button_class = GTK_TOOL_BUTTON_CLASS (class); tool_button_class->clicked = menu_tool_button_clicked; } -- cgit v1.2.3