diff options
-rw-r--r-- | a11y/widgets/Makefile.am | 2 | ||||
-rw-r--r-- | a11y/widgets/ea-combo-button.c | 169 | ||||
-rw-r--r-- | a11y/widgets/ea-combo-button.h | 35 | ||||
-rw-r--r-- | a11y/widgets/ea-widgets.c | 7 | ||||
-rw-r--r-- | a11y/widgets/ea-widgets.h | 1 | ||||
-rw-r--r-- | shell/e-shell-window-actions.c | 149 | ||||
-rw-r--r-- | shell/e-shell-window-private.c | 104 | ||||
-rw-r--r-- | shell/e-shell-window-private.h | 38 | ||||
-rw-r--r-- | shell/e-shell-window.c | 76 | ||||
-rw-r--r-- | shell/e-shell-window.h | 2 | ||||
-rw-r--r-- | shell/e-shell.c | 36 | ||||
-rw-r--r-- | shell/e-shell.h | 13 | ||||
-rw-r--r-- | shell/main.c | 21 | ||||
-rw-r--r-- | shell/test/e-test-shell-module.c | 48 | ||||
-rw-r--r-- | widgets/misc/Makefile.am | 4 | ||||
-rw-r--r-- | widgets/misc/e-combo-button.c | 623 | ||||
-rw-r--r-- | widgets/misc/e-combo-button.h | 83 | ||||
-rw-r--r-- | widgets/misc/e-menu-tool-button.c | 148 | ||||
-rw-r--r-- | widgets/misc/e-menu-tool-button.h | 67 | ||||
-rw-r--r-- | widgets/misc/e-preferences-window.c | 11 |
20 files changed, 523 insertions, 1114 deletions
diff --git a/a11y/widgets/Makefile.am b/a11y/widgets/Makefile.am index e157f82188..e7d10dc516 100644 --- a/a11y/widgets/Makefile.am +++ b/a11y/widgets/Makefile.am @@ -20,8 +20,6 @@ libevolution_widgets_a11y_la_SOURCES = \ ea-calendar-item.h \ ea-calendar-cell.c \ ea-calendar-cell.h \ - ea-combo-button.c \ - ea-combo-button.h \ ea-expander.c \ ea-expander.h \ ea-widgets.c \ diff --git a/a11y/widgets/ea-combo-button.c b/a11y/widgets/ea-combo-button.c deleted file mode 100644 index 9886cc4221..0000000000 --- a/a11y/widgets/ea-combo-button.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Authors: Harry Lu <harry.lu@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - */ - -#include <config.h> -#include "ea-combo-button.h" -#include <gtk/gtk.h> -#include <glib/gi18n.h> - -static AtkObjectClass *parent_class; -static GType parent_type; - -/*Action IDs */ -enum { - ACTIVATE_DEFAULT, - POPUP_MENU, - LAST_ACTION -}; - -/* Static functions */ -static G_CONST_RETURN gchar* -ea_combo_button_get_name (AtkObject *a11y) -{ - GtkWidget *widget; - GtkWidget *label; - EComboButton *button; - - widget = GTK_ACCESSIBLE (a11y)->widget; - if (!widget) - return NULL; - - button = E_COMBO_BUTTON (widget); - label = e_combo_button_get_label (button); - if (label) - return gtk_label_get_text (GTK_LABEL (label)); - - return _("Combo Button"); -} - -/* Action interface */ -static G_CONST_RETURN gchar * -ea_combo_button_action_get_name (AtkAction *action, gint i) -{ - switch (i) - { - case ACTIVATE_DEFAULT: - return _("Activate Default"); - case POPUP_MENU: - return _("Popup Menu"); - default: - return NULL; - } -} - -static gboolean -ea_combo_button_do_action (AtkAction *action, - gint i) -{ - GtkWidget *widget; - EComboButton *button; - - widget = GTK_ACCESSIBLE (action)->widget; - if (!widget || !GTK_WIDGET_IS_SENSITIVE (widget) || !GTK_WIDGET_VISIBLE (widget)) - return FALSE; - - button = E_COMBO_BUTTON (widget); - - switch (i) - { - case ACTIVATE_DEFAULT: - g_signal_emit_by_name (button, "activate_default"); - return TRUE; - case POPUP_MENU: - return e_combo_button_popup_menu (button); - default: - return FALSE; - } -} - -static gint -ea_combo_button_get_n_actions (AtkAction *action) -{ - return LAST_ACTION; -} - -static void -atk_action_interface_init (AtkActionIface *iface) -{ - g_return_if_fail (iface != NULL); - - iface->do_action = ea_combo_button_do_action; - iface->get_n_actions = ea_combo_button_get_n_actions; - iface->get_name = ea_combo_button_action_get_name; -} - -static void -ea_combo_button_class_init (EaComboButtonClass *klass) -{ - AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (klass); - - parent_class = g_type_class_ref (parent_type); - - atk_object_class->get_name = ea_combo_button_get_name; -} - -static void -ea_combo_button_init (EaComboButton *a11y) -{ - /* Empty for now */ -} - -GType -ea_combo_button_get_type (void) -{ - static GType type = 0; - - if (!type) { - AtkObjectFactory *factory; - GTypeQuery query; - - GTypeInfo info = { - sizeof (EaComboButtonClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) ea_combo_button_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (EaComboButton), - 0, - (GInstanceInitFunc) ea_combo_button_init, - NULL /* value_tree */ - }; - - static const GInterfaceInfo atk_action_info = { - (GInterfaceInitFunc) atk_action_interface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - - factory = atk_registry_get_factory (atk_get_default_registry (), GTK_TYPE_BUTTON); - parent_type = atk_object_factory_get_accessible_type (factory); - g_type_query (parent_type, &query); - - info.class_size = query.class_size; - info.instance_size = query.instance_size; - - type = g_type_register_static (parent_type, "EaComboButton", &info, 0); - g_type_add_interface_static (type, ATK_TYPE_ACTION, - &atk_action_info); - - } - - return type; -} - -AtkObject * -ea_combo_button_new (GtkWidget *widget) -{ - EaComboButton *a11y; - - a11y = g_object_new (ea_combo_button_get_type (), NULL); - - GTK_ACCESSIBLE (a11y)->widget = GTK_WIDGET (widget); - ATK_OBJECT (a11y)->role = ATK_ROLE_PUSH_BUTTON; - - return ATK_OBJECT (a11y); -} diff --git a/a11y/widgets/ea-combo-button.h b/a11y/widgets/ea-combo-button.h deleted file mode 100644 index 339c697e4a..0000000000 --- a/a11y/widgets/ea-combo-button.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Authors: Harry Lu <harry.lu@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - */ - -#ifndef __EA_COMBO_BUTTON_H_ -#define __EA_COMBO_BUTTON_H_ - -#include <gtk/gtk.h> -#include <misc/e-combo-button.h> - -#define EA_TYPE_COMBO_BUTTON (ea_combo_button_get_type ()) -#define EA_COMBO_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_COMBO_BUTTON, EaComboButton)) -#define EA_COMBO_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_COMBO_BUTTON, EaComboButtonClass)) -#define EA_IS_COMBO_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_COMBO_BUTTON)) -#define EA_IS_COMBO_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_COMBO_BUTTON)) - -typedef struct _EaComboButton EaComboButton; -typedef struct _EaComboButtonClass EaComboButtonClass; - -struct _EaComboButton { - GtkAccessible object; -}; - -struct _EaComboButtonClass { - GtkAccessibleClass parent_class; -}; - - -/* Standard Glib function */ -GType ea_combo_button_get_type (void); -AtkObject *ea_combo_button_new (GtkWidget *combo_button); - -#endif /* ! __EA_COMBO_BUTTON_H_ */ diff --git a/a11y/widgets/ea-widgets.c b/a11y/widgets/ea-widgets.c index 6949afb7d0..9143492adc 100644 --- a/a11y/widgets/ea-widgets.c +++ b/a11y/widgets/ea-widgets.c @@ -25,12 +25,10 @@ #include "ea-factory.h" #include "widgets/ea-calendar-item.h" -#include "widgets/ea-combo-button.h" #include "widgets/ea-expander.h" #include "ea-widgets.h" EA_FACTORY_GOBJECT (EA_TYPE_CALENDAR_ITEM, ea_calendar_item, ea_calendar_item_new) -EA_FACTORY (EA_TYPE_COMBO_BUTTON, ea_combo_button, ea_combo_button_new) EA_FACTORY (EA_TYPE_EXPANDER, ea_expander, ea_expander_new) void e_calendar_item_a11y_init (void) @@ -38,11 +36,6 @@ void e_calendar_item_a11y_init (void) EA_SET_FACTORY (e_calendar_item_get_type (), ea_calendar_item); } -void e_combo_button_a11y_init (void) -{ - EA_SET_FACTORY (e_combo_button_get_type (), ea_combo_button); -} - void e_expander_a11y_init (void) { EA_SET_FACTORY (e_expander_get_type (), ea_expander); diff --git a/a11y/widgets/ea-widgets.h b/a11y/widgets/ea-widgets.h index 877da03051..7b8b3d8513 100644 --- a/a11y/widgets/ea-widgets.h +++ b/a11y/widgets/ea-widgets.h @@ -30,7 +30,6 @@ #define _EA_WIDGETS_H__ void e_calendar_item_a11y_init (void); -void e_combo_button_a11y_init (void); void e_expander_a11y_init (void); #endif /* _EA_WIDGETS_H__ */ diff --git a/shell/e-shell-window-actions.c b/shell/e-shell-window-actions.c index bc1fcea27b..24588b4931 100644 --- a/shell/e-shell-window-actions.c +++ b/shell/e-shell-window-actions.c @@ -20,14 +20,16 @@ #include "e-shell-window-private.h" -#include "e-shell.h" -#include "e-shell-importer.h" +#include <string.h> -#include "e-util/e-dialog-utils.h" -#include "e-util/e-error.h" -#include "e-util/e-print.h" +#include <e-shell.h> +#include <e-shell-importer.h> + +#include <e-util/e-dialog-utils.h> +#include <e-util/e-error.h> +#include <e-util/e-print.h> +#include <e-util/e-util.h> -#include <string.h> #include <libedataserverui/e-passwords.h> #define EVOLUTION_COPYRIGHT \ @@ -626,7 +628,7 @@ static const gchar *documenters[] = { static void action_about_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { gchar *translator_credits; @@ -638,7 +640,7 @@ action_about_cb (GtkAction *action, translator_credits = NULL; gtk_show_about_dialog ( - GTK_WINDOW (window), + GTK_WINDOW (shell_window), "program-name", "Evolution", "version", VERSION, "copyright", EVOLUTION_COPYRIGHT, @@ -654,9 +656,9 @@ action_about_cb (GtkAction *action, static void action_close_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { - GtkWidget *widget = GTK_WIDGET (window); + GtkWidget *widget = GTK_WIDGET (shell_window); GdkEvent *event; /* Synthesize a delete_event on this window. */ @@ -669,14 +671,14 @@ action_close_cb (GtkAction *action, static void action_contents_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { - /* FIXME Unfinished. */ + e_display_help (GTK_WINDOW (shell_window), NULL); } static void action_faq_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { GError *error = NULL; @@ -691,12 +693,12 @@ action_faq_cb (GtkAction *action, static void action_forget_passwords_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { gint response; response = e_error_run ( - GTK_WINDOW (window), "shell:forget-passwords", NULL); + GTK_WINDOW (shell_window), "shell:forget-passwords", NULL); if (response == GTK_RESPONSE_OK) e_passwords_forget_passwords (); @@ -704,31 +706,31 @@ action_forget_passwords_cb (GtkAction *action, static void action_import_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { - e_shell_importer_start_import (window); + e_shell_importer_start_import (shell_window); } static void action_new_window_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { EShell *shell; - shell = e_shell_window_get_shell (window); + shell = e_shell_window_get_shell (shell_window); e_shell_create_window (shell); } static void action_page_setup_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { - e_print_run_page_setup_dialog (GTK_WINDOW (window)); + e_print_run_page_setup_dialog (GTK_WINDOW (shell_window)); } static void action_preferences_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { GtkWidget *preferences_window; @@ -740,7 +742,7 @@ action_preferences_cb (GtkAction *action, static void action_quick_reference_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { const gchar * const *language_names; @@ -785,86 +787,86 @@ action_quick_reference_cb (GtkAction *action, static void action_quit_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { EShell *shell; - shell = e_shell_window_get_shell (window); + shell = e_shell_window_get_shell (shell_window); e_shell_quit (shell); } static void action_send_receive_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { EShell *shell; - shell = e_shell_window_get_shell (window); - e_shell_send_receive (shell, GTK_WINDOW (window)); + shell = e_shell_window_get_shell (shell_window); + e_shell_send_receive (shell, GTK_WINDOW (shell_window)); } static void action_shell_view_cb (GtkRadioAction *action, GtkRadioAction *current, - EShellWindow *window) + EShellWindow *shell_window) { const gchar *view_name; view_name = g_object_get_data (G_OBJECT (current), "view-name"); - e_shell_window_set_current_view (window, view_name); + e_shell_window_set_current_view (shell_window, view_name); } static void action_show_sidebar_cb (GtkToggleAction *action, - EShellWindow *window) + EShellWindow *shell_window) { GtkWidget *widget; gboolean active; - widget = window->priv->sidebar; + widget = shell_window->priv->sidebar; active = gtk_toggle_action_get_active (action); g_object_set (widget, "visible", active, NULL); } static void action_show_statusbar_cb (GtkToggleAction *action, - EShellWindow *window) + EShellWindow *shell_window) { GtkWidget *widget; gboolean active; - widget = window->priv->status_area; + widget = shell_window->priv->status_area; active = gtk_toggle_action_get_active (action); g_object_set (widget, "visible", active, NULL); } static void action_show_switcher_cb (GtkToggleAction *action, - EShellWindow *window) + EShellWindow *shell_window) { ESidebar *sidebar; gboolean active; - sidebar = E_SIDEBAR (window->priv->sidebar); + sidebar = E_SIDEBAR (shell_window->priv->sidebar); active = gtk_toggle_action_get_active (action); e_sidebar_set_actions_visible (sidebar, active); } static void action_show_toolbar_cb (GtkToggleAction *action, - EShellWindow *window) + EShellWindow *shell_window) { GtkWidget *widget; gboolean active; - widget = window->priv->main_toolbar; + widget = shell_window->priv->main_toolbar; active = gtk_toggle_action_get_active (action); g_object_set (widget, "visible", active, NULL); } static void action_submit_bug_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { const gchar *command_line; GError *error = NULL; @@ -881,7 +883,7 @@ action_submit_bug_cb (GtkAction *action, message = _("Bug Buddy is not installed."); else message = _("Bug Buddy could not be run."); - e_notice (window, GTK_MESSAGE_ERROR, message); + e_notice (shell_window, GTK_MESSAGE_ERROR, message); g_error_free (error); } } @@ -889,12 +891,12 @@ action_submit_bug_cb (GtkAction *action, static void action_switcher_style_cb (GtkRadioAction *action, GtkRadioAction *current, - EShellWindow *window) + EShellWindow *shell_window) { ESidebar *sidebar; GtkToolbarStyle style; - sidebar = E_SIDEBAR (window->priv->sidebar); + sidebar = E_SIDEBAR (shell_window->priv->sidebar); style = gtk_radio_action_get_current_value (action); switch (style) { @@ -913,7 +915,7 @@ action_switcher_style_cb (GtkRadioAction *action, static void action_sync_options_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { const gchar *command_line; GError *error = NULL; @@ -930,28 +932,28 @@ action_sync_options_cb (GtkAction *action, message = _("GNOME Pilot is not installed."); else message = _("GNOME Pilot could not be run."); - e_notice (window, GTK_MESSAGE_ERROR, message); + e_notice (shell_window, GTK_MESSAGE_ERROR, message); g_error_free (error); } } static void action_work_offline_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { EShell *shell; - shell = e_shell_window_get_shell (window); + shell = e_shell_window_get_shell (shell_window); e_shell_set_line_status (shell, E_SHELL_LINE_STATUS_OFFLINE); } static void action_work_online_cb (GtkAction *action, - EShellWindow *window) + EShellWindow *shell_window) { EShell *shell; - shell = e_shell_window_get_shell (window); + shell = e_shell_window_get_shell (shell_window); e_shell_set_line_status (shell, E_SHELL_LINE_STATUS_ONLINE); } @@ -1102,7 +1104,7 @@ static GtkActionEntry shell_entries[] = { { "new-menu", GTK_STOCK_NEW, N_("_New"), - NULL, + "", NULL, NULL }, @@ -1223,7 +1225,7 @@ shell_window_compare_actions (GtkAction *action1, } static void -shell_window_extract_actions (EShellWindow *window, +shell_window_extract_actions (EShellWindow *shell_window, GList **source_list, GList **destination_list) { @@ -1235,7 +1237,7 @@ shell_window_extract_actions (EShellWindow *window, * as belonging to the current EShellView and move them to the * destination list. */ - current_view = e_shell_window_get_current_view (window); + current_view = e_shell_window_get_current_view (shell_window); /* Example: Suppose [A] and [C] are tagged for this EShellView. * @@ -1273,51 +1275,51 @@ shell_window_extract_actions (EShellWindow *window, } void -e_shell_window_actions_init (EShellWindow *window) +e_shell_window_actions_init (EShellWindow *shell_window) { GtkActionGroup *action_group; GtkUIManager *manager; const gchar *domain; - g_return_if_fail (E_IS_SHELL_WINDOW (window)); + g_return_if_fail (E_IS_SHELL_WINDOW (shell_window)); - manager = e_shell_window_get_ui_manager (window); + manager = e_shell_window_get_ui_manager (shell_window); domain = GETTEXT_PACKAGE; /* Shell Actions */ - action_group = window->priv->shell_actions; + action_group = shell_window->priv->shell_actions; gtk_action_group_set_translation_domain (action_group, domain); gtk_action_group_add_actions ( action_group, shell_entries, - G_N_ELEMENTS (shell_entries), window); + G_N_ELEMENTS (shell_entries), shell_window); gtk_action_group_add_toggle_actions ( action_group, shell_toggle_entries, - G_N_ELEMENTS (shell_toggle_entries), window); + G_N_ELEMENTS (shell_toggle_entries), shell_window); gtk_action_group_add_radio_actions ( action_group, shell_switcher_style_entries, G_N_ELEMENTS (shell_switcher_style_entries), E_SIDEBAR_DEFAULT_TOOLBAR_STYLE, - G_CALLBACK (action_switcher_style_cb), window); + G_CALLBACK (action_switcher_style_cb), shell_window); gtk_ui_manager_insert_action_group (manager, action_group, 0); /* New Item Actions (empty) */ - action_group = window->priv->new_item_actions; + action_group = shell_window->priv->new_item_actions; gtk_action_group_set_translation_domain (action_group, domain); gtk_ui_manager_insert_action_group (manager, action_group, 0); /* New Source Actions (empty) */ - action_group = window->priv->new_source_actions; + action_group = shell_window->priv->new_source_actions; gtk_action_group_set_translation_domain (action_group, domain); gtk_ui_manager_insert_action_group (manager, action_group, 0); /* Shell View Actions (empty) */ - action_group = window->priv->shell_view_actions; + action_group = shell_window->priv->shell_view_actions; gtk_action_group_set_translation_domain (action_group, domain); gtk_ui_manager_insert_action_group (manager, action_group, 0); } GtkWidget * -e_shell_window_create_new_menu (EShellWindow *window) +e_shell_window_create_new_menu (EShellWindow *shell_window) { GtkActionGroup *action_group; GList *new_item_actions; @@ -1328,13 +1330,13 @@ e_shell_window_create_new_menu (EShellWindow *window) /* Get sorted lists of "new item" and "new source" actions. */ - action_group = window->priv->new_item_actions; + action_group = shell_window->priv->new_item_actions; new_item_actions = g_list_sort ( gtk_action_group_list_actions (action_group), (GCompareFunc) shell_window_compare_actions); - action_group = window->priv->new_source_actions; + action_group = shell_window->priv->new_source_actions; new_source_actions = g_list_sort ( gtk_action_group_list_actions (action_group), @@ -1343,10 +1345,10 @@ e_shell_window_create_new_menu (EShellWindow *window) /* Give priority to actions that belong to this shell view. */ shell_window_extract_actions ( - window, &new_item_actions, &list); + shell_window, &new_item_actions, &list); shell_window_extract_actions ( - window, &new_source_actions, &list); + shell_window, &new_source_actions, &list); /* Convert the actions to menu item proxy widgets. */ @@ -1388,7 +1390,7 @@ e_shell_window_create_new_menu (EShellWindow *window) } void -e_shell_window_create_shell_view_actions (EShellWindow *window) +e_shell_window_create_shell_view_actions (EShellWindow *shell_window) { GType *children; GSList *group = NULL; @@ -1397,11 +1399,11 @@ e_shell_window_create_shell_view_actions (EShellWindow *window) guint n_children, ii; guint merge_id; - g_return_if_fail (E_IS_SHELL_WINDOW (window)); + g_return_if_fail (E_IS_SHELL_WINDOW (shell_window)); - action_group = window->priv->shell_view_actions; + action_group = shell_window->priv->shell_view_actions; children = g_type_children (E_TYPE_SHELL_VIEW, &n_children); - manager = e_shell_window_get_ui_manager (window); + manager = e_shell_window_get_ui_manager (shell_window); merge_id = gtk_ui_manager_new_merge_id (manager); /* Construct a group of radio actions from the various EShellView @@ -1454,12 +1456,13 @@ e_shell_window_create_shell_view_actions (EShellWindow *window) if (group == NULL) { /* First view is the default. */ - window->priv->default_view = view_name; + shell_window->priv->default_view = view_name; /* Only listen to the first action. */ g_signal_connect ( action, "changed", - G_CALLBACK (action_shell_view_cb), window); + G_CALLBACK (action_shell_view_cb), + shell_window); } gtk_radio_action_set_group (action, group); @@ -1469,7 +1472,7 @@ e_shell_window_create_shell_view_actions (EShellWindow *window) action_group, GTK_ACTION (action)); e_sidebar_add_action ( - E_SIDEBAR (window->priv->sidebar), + E_SIDEBAR (shell_window->priv->sidebar), GTK_ACTION (action)); gtk_ui_manager_add_ui ( diff --git a/shell/e-shell-window-private.c b/shell/e-shell-window-private.c index 4953c9fecf..5b4c1e40ba 100644 --- a/shell/e-shell-window-private.c +++ b/shell/e-shell-window-private.c @@ -25,9 +25,29 @@ #include <e-util/gconf-bridge.h> static void +shell_window_notify_current_view_cb (EShellWindow *shell_window) +{ + GtkWidget *menu; + GtkWidget *widget; + const gchar *path; + + /* Update the "File -> New" submenu. */ + path = "/main-menu/file-menu/new-menu"; + menu = e_shell_window_create_new_menu (shell_window); + widget = e_shell_window_get_managed_widget (shell_window, path); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (widget), menu); + gtk_widget_show (widget); + + /* Update the "New" menu tool button submenu. */ + menu = e_shell_window_create_new_menu (shell_window); + widget = shell_window->priv->menu_tool_button; + gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (widget), menu); +} + +static void shell_window_save_switcher_style_cb (GtkRadioAction *action, GtkRadioAction *current, - EShellWindow *window) + EShellWindow *shell_window) { GConfClient *client; GtkToolbarStyle style; @@ -67,7 +87,7 @@ shell_window_save_switcher_style_cb (GtkRadioAction *action, } static void -shell_window_init_switcher_style (EShellWindow *window) +shell_window_init_switcher_style (EShellWindow *shell_window) { GtkAction *action; GConfClient *client; @@ -100,13 +120,14 @@ shell_window_init_switcher_style (EShellWindow *window) g_signal_connect ( action, "changed", - G_CALLBACK (shell_window_save_switcher_style_cb), window); + G_CALLBACK (shell_window_save_switcher_style_cb), + shell_window); g_object_unref (client); } static void -shell_window_menu_item_select_cb (EShellWindow *window, +shell_window_menu_item_select_cb (EShellWindow *shell_window, GtkWidget *menu_item) { GtkAction *action; @@ -121,23 +142,23 @@ shell_window_menu_item_select_cb (EShellWindow *window, if (tooltip == NULL) return; - label = GTK_LABEL (window->priv->tooltip_label); + label = GTK_LABEL (shell_window->priv->tooltip_label); gtk_label_set_text (label, tooltip); g_free (tooltip); - gtk_widget_show (window->priv->tooltip_label); - gtk_widget_hide (window->priv->status_notebook); + gtk_widget_show (shell_window->priv->tooltip_label); + gtk_widget_hide (shell_window->priv->status_notebook); } static void -shell_window_menu_item_deselect_cb (EShellWindow *window) +shell_window_menu_item_deselect_cb (EShellWindow *shell_window) { - gtk_widget_hide (window->priv->tooltip_label); - gtk_widget_show (window->priv->status_notebook); + gtk_widget_hide (shell_window->priv->tooltip_label); + gtk_widget_show (shell_window->priv->status_notebook); } static void -shell_window_connect_proxy_cb (EShellWindow *window, +shell_window_connect_proxy_cb (EShellWindow *shell_window, GtkAction *action, GtkWidget *proxy) { @@ -151,16 +172,18 @@ shell_window_connect_proxy_cb (EShellWindow *window, g_signal_connect_swapped ( proxy, "select", - G_CALLBACK (shell_window_menu_item_select_cb), window); + G_CALLBACK (shell_window_menu_item_select_cb), + shell_window); g_signal_connect_swapped ( proxy, "deselect", - G_CALLBACK (shell_window_menu_item_deselect_cb), window); + G_CALLBACK (shell_window_menu_item_deselect_cb), + shell_window); } static void shell_window_online_button_clicked_cb (EOnlineButton *button, - EShellWindow *window) + EShellWindow *shell_window) { if (e_online_button_get_online (button)) gtk_action_activate (ACTION (WORK_OFFLINE)); @@ -169,11 +192,12 @@ shell_window_online_button_clicked_cb (EOnlineButton *button, } void -e_shell_window_private_init (EShellWindow *window) +e_shell_window_private_init (EShellWindow *shell_window) { - EShellWindowPrivate *priv = window->priv; + EShellWindowPrivate *priv = shell_window->priv; GHashTable *loaded_views; GConfBridge *bridge; + GtkToolItem *item; GtkWidget *container; GtkWidget *widget; GObject *object; @@ -194,34 +218,42 @@ e_shell_window_private_init (EShellWindow *window) e_load_ui_definition (priv->manager, "evolution-shell.ui"); - e_shell_window_actions_init (window); + e_shell_window_actions_init (shell_window); gtk_window_add_accel_group ( - GTK_WINDOW (window), + GTK_WINDOW (shell_window), gtk_ui_manager_get_accel_group (priv->manager)); g_signal_connect_swapped ( priv->manager, "connect-proxy", - G_CALLBACK (shell_window_connect_proxy_cb), window); + G_CALLBACK (shell_window_connect_proxy_cb), shell_window); /* Construct window widgets. */ widget = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (window), widget); + gtk_container_add (GTK_CONTAINER (shell_window), widget); gtk_widget_show (widget); container = widget; - widget = e_shell_window_get_managed_widget (window, "/main-menu"); + widget = e_shell_window_get_managed_widget ( + shell_window, "/main-menu"); gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); priv->main_menu = g_object_ref (widget); gtk_widget_show (widget); - widget = e_shell_window_get_managed_widget (window, "/main-toolbar"); + widget = e_shell_window_get_managed_widget ( + shell_window, "/main-toolbar"); gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); priv->main_toolbar = g_object_ref (widget); gtk_widget_show (widget); + item = e_menu_tool_button_new (_("New")); + gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE); + gtk_toolbar_insert (GTK_TOOLBAR (widget), item, 0); + priv->menu_tool_button = g_object_ref (item); + gtk_widget_show (GTK_WIDGET (item)); + widget = gtk_hpaned_new (); gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); priv->content_pane = g_object_ref (widget); @@ -264,7 +296,8 @@ e_shell_window_private_init (EShellWindow *window) widget = e_online_button_new (); g_signal_connect ( widget, "clicked", - G_CALLBACK (shell_window_online_button_clicked_cb), window); + G_CALLBACK (shell_window_online_button_clicked_cb), + shell_window); gtk_box_pack_start (GTK_BOX (container), widget, FALSE, TRUE, 0); priv->online_button = g_object_ref (widget); gtk_widget_show (widget); @@ -288,7 +321,7 @@ e_shell_window_private_init (EShellWindow *window) key = "/apps/evolution/shell/view_defaults/window"; gconf_bridge_bind_window ( - bridge, key, GTK_WINDOW (window), TRUE, FALSE); + bridge, key, GTK_WINDOW (shell_window), TRUE, FALSE); object = G_OBJECT (priv->content_pane); key = "/apps/evolution/shell/view_defaults/folder_bar/width"; @@ -310,17 +343,25 @@ e_shell_window_private_init (EShellWindow *window) key = "/apps/evolution/shell/view_defaults/toolbar_visible"; gconf_bridge_bind_property (bridge, key, object, "active"); - shell_window_init_switcher_style (window); + shell_window_init_switcher_style (shell_window); + + /* Fine tuning. */ + + g_object_set (ACTION (SEND_RECEIVE), "is-important", TRUE, NULL); + + g_signal_connect ( + shell_window, "notify::current-view", + G_CALLBACK (shell_window_notify_current_view_cb), NULL); - /* Initialize shell views */ + /* Initialize shell views. */ - e_shell_window_create_shell_view_actions (window); + e_shell_window_create_shell_view_actions (shell_window); } void -e_shell_window_private_dispose (EShellWindow *window) +e_shell_window_private_dispose (EShellWindow *shell_window) { - EShellWindowPrivate *priv = window->priv; + EShellWindowPrivate *priv = shell_window->priv; DISPOSE (priv->shell); @@ -334,6 +375,7 @@ e_shell_window_private_dispose (EShellWindow *window) DISPOSE (priv->main_menu); DISPOSE (priv->main_toolbar); + DISPOSE (priv->menu_tool_button); DISPOSE (priv->content_pane); DISPOSE (priv->content_notebook); DISPOSE (priv->sidebar); @@ -347,9 +389,9 @@ e_shell_window_private_dispose (EShellWindow *window) } void -e_shell_window_private_finalize (EShellWindow *window) +e_shell_window_private_finalize (EShellWindow *shell_window) { - EShellWindowPrivate *priv = window->priv; + EShellWindowPrivate *priv = shell_window->priv; g_hash_table_destroy (priv->loaded_views); } diff --git a/shell/e-shell-window-private.h b/shell/e-shell-window-private.h index ac1ed1f187..db8174832d 100644 --- a/shell/e-shell-window-private.h +++ b/shell/e-shell-window-private.h @@ -25,21 +25,24 @@ #include <glib/gi18n.h> -#include "e-shell.h" -#include "e-shell-view.h" -#include "e-shell-registry.h" -#include "e-shell-window-actions.h" +#include <e-shell.h> +#include <e-shell-view.h> +#include <e-shell-registry.h> +#include <e-shell-window-actions.h> -#include "e-online-button.h" -#include "e-sidebar.h" +#include <e-menu-tool-button.h> +#include <e-online-button.h> +#include <e-sidebar.h> #define E_SHELL_WINDOW_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE \ ((obj), E_TYPE_SHELL_WINDOW, EShellWindowPrivate)) -/* Shorthand, requires a variable named "window". */ -#define ACTION(name) (E_SHELL_WINDOW_ACTION_##name (window)) -#define ACTION_GROUP(name) (E_SHELL_WINDOW_ACTION_GROUP_##name (window)) +/* Shorthand, requires a variable named "shell_window". */ +#define ACTION(name) \ + (E_SHELL_WINDOW_ACTION_##name (shell_window)) +#define ACTION_GROUP(name) \ + (E_SHELL_WINDOW_ACTION_GROUP_##name (shell_window)) /* For use in dispose() methods. */ #define DISPOSE(obj) \ @@ -71,6 +74,7 @@ struct _EShellWindowPrivate { GtkWidget *main_menu; GtkWidget *main_toolbar; + GtkWidget *menu_tool_button; GtkWidget *content_pane; GtkWidget *content_notebook; GtkWidget *sidebar; @@ -82,20 +86,20 @@ struct _EShellWindowPrivate { /* Miscellaneous */ - gboolean destroyed; /* XXX Do we still need this? */ - gboolean safe_mode; + guint destroyed : 1; /* XXX Do we still need this? */ + guint safe_mode : 1; }; -void e_shell_window_private_init (EShellWindow *window); -void e_shell_window_private_dispose (EShellWindow *window); -void e_shell_window_private_finalize (EShellWindow *window); +void e_shell_window_private_init (EShellWindow *shell_window); +void e_shell_window_private_dispose (EShellWindow *shell_window); +void e_shell_window_private_finalize (EShellWindow *shell_window); /* Private Utilities */ -void e_shell_window_actions_init (EShellWindow *window); -GtkWidget * e_shell_window_create_new_menu (EShellWindow *window); +void e_shell_window_actions_init (EShellWindow *shell_window); +GtkWidget * e_shell_window_create_new_menu (EShellWindow *shell_window); void e_shell_window_create_shell_view_actions - (EShellWindow *window); + (EShellWindow *shell_window); G_END_DECLS diff --git a/shell/e-shell-window.c b/shell/e-shell-window.c index c12e6ecc64..c29f7d10e8 100644 --- a/shell/e-shell-window.c +++ b/shell/e-shell-window.c @@ -18,26 +18,20 @@ * Boston, MA 02110-1301, USA. */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - #include "e-shell-window-private.h" -#include "e-util/e-plugin-ui.h" -#include "e-util/e-util-private.h" -#include "e-util/gconf-bridge.h" -#include "widgets/misc/e-online-button.h" - -#include "e-sidebar.h" -#include "es-menu.h" -#include "es-event.h" - +#include <string.h> #include <glib/gi18n.h> - #include <gconf/gconf-client.h> -#include <string.h> +#include <e-sidebar.h> +#include <es-event.h> +#include <es-menu.h> + +#include <e-util/e-plugin-ui.h> +#include <e-util/e-util-private.h> +#include <e-util/gconf-bridge.h> +#include <widgets/misc/e-online-button.h> enum { PROP_0, @@ -49,11 +43,41 @@ enum { static gpointer parent_class; static void +shell_window_online_mode_notify_cb (EShell *shell, + GParamSpec *pspec, + EShellWindow *shell_window) +{ + GtkAction *action; + EOnlineButton *online_button; + gboolean online_mode; + + online_mode = e_shell_get_online_mode (shell); + + action = ACTION (WORK_OFFLINE); + gtk_action_set_sensitive (action, TRUE); + gtk_action_set_visible (action, online_mode); + + action = ACTION (WORK_ONLINE); + gtk_action_set_sensitive (action, TRUE); + gtk_action_set_visible (action, !online_mode); + + online_button = E_ONLINE_BUTTON (shell_window->priv->online_button); + e_online_button_set_online (online_button, online_mode); +} + +static void shell_window_set_shell (EShellWindow *shell_window, EShell *shell) { g_return_if_fail (shell_window->priv->shell == NULL); shell_window->priv->shell = g_object_ref (shell); + + g_signal_connect ( + shell, "notify::online-mode", + G_CALLBACK (shell_window_online_mode_notify_cb), + shell_window); + + g_object_notify (G_OBJECT (shell), "online-mode"); } static void @@ -226,8 +250,8 @@ e_shell_window_new (EShell *shell, gboolean safe_mode) { return g_object_new ( - E_TYPE_SHELL_WINDOW, "shell", shell, - "safe-mode", safe_mode, NULL); + E_TYPE_SHELL_WINDOW, + "shell", shell, "safe-mode", safe_mode, NULL); } EShell * @@ -372,6 +396,8 @@ e_shell_window_register_new_item_actions (EShellWindow *shell_window, guint n_entries) { GtkActionGroup *action_group; + GtkAccelGroup *accel_group; + GtkUIManager *manager; guint ii; g_return_if_fail (E_IS_SHELL_WINDOW (shell_window)); @@ -379,6 +405,8 @@ e_shell_window_register_new_item_actions (EShellWindow *shell_window, g_return_if_fail (entries != NULL); action_group = shell_window->priv->new_item_actions; + manager = e_shell_window_get_ui_manager (shell_window); + accel_group = gtk_ui_manager_get_accel_group (manager); module_name = g_intern_string (module_name); gtk_action_group_add_actions ( @@ -397,10 +425,15 @@ e_shell_window_register_new_item_actions (EShellWindow *shell_window, action = gtk_action_group_get_action ( action_group, action_name); + gtk_action_set_accel_group (action, accel_group); + g_object_set_data ( G_OBJECT (action), "module-name", (gpointer) module_name); } + + /* Force a rebuild of the "New" menu. */ + g_object_notify (G_OBJECT (shell_window), "current-view"); } void @@ -410,6 +443,8 @@ e_shell_window_register_new_source_actions (EShellWindow *shell_window, guint n_entries) { GtkActionGroup *action_group; + GtkAccelGroup *accel_group; + GtkUIManager *manager; guint ii; g_return_if_fail (E_IS_SHELL_WINDOW (shell_window)); @@ -417,6 +452,8 @@ e_shell_window_register_new_source_actions (EShellWindow *shell_window, g_return_if_fail (entries != NULL); action_group = shell_window->priv->new_source_actions; + manager = e_shell_window_get_ui_manager (shell_window); + accel_group = gtk_ui_manager_get_accel_group (manager); module_name = g_intern_string (module_name); gtk_action_group_add_actions ( @@ -435,8 +472,13 @@ e_shell_window_register_new_source_actions (EShellWindow *shell_window, action = gtk_action_group_get_action ( action_group, action_name); + gtk_action_set_accel_group (action, accel_group); + g_object_set_data ( G_OBJECT (action), "module-name", (gpointer) module_name); } + + /* Force a rebuild of the "New" menu. */ + g_object_notify (G_OBJECT (shell_window), "current-view"); } diff --git a/shell/e-shell-window.h b/shell/e-shell-window.h index f4f74f293b..0ec9b15e5f 100644 --- a/shell/e-shell-window.h +++ b/shell/e-shell-window.h @@ -77,7 +77,7 @@ gboolean e_shell_window_get_safe_mode (EShellWindow *shell_window); void e_shell_window_set_safe_mode (EShellWindow *shell_window, gboolean safe_mode); -/* These should be called from the shell module's window_created() method. */ +/* These should be called from the shell module's window_created() handler. */ void e_shell_window_register_new_item_actions (EShellWindow *shell_window, diff --git a/shell/e-shell.c b/shell/e-shell.c index 6ef5de27c5..b96ceb4944 100644 --- a/shell/e-shell.c +++ b/shell/e-shell.c @@ -39,13 +39,13 @@ struct _EShellPrivate { GList *active_windows; EShellLineStatus line_status; - guint online : 1; - guint safe_mode : 1; + guint online_mode : 1; + guint safe_mode : 1; }; enum { PROP_0, - PROP_ONLINE + PROP_ONLINE_MODE }; enum { @@ -145,8 +145,8 @@ shell_set_property (GObject *object, GParamSpec *pspec) { switch (property_id) { - case PROP_ONLINE: - e_shell_set_online ( + case PROP_ONLINE_MODE: + e_shell_set_online_mode ( E_SHELL (object), g_value_get_boolean (value)); return; @@ -162,9 +162,9 @@ shell_get_property (GObject *object, GParamSpec *pspec) { switch (property_id) { - case PROP_ONLINE: + case PROP_ONLINE_MODE: g_value_set_boolean ( - value, e_shell_get_online ( + value, e_shell_get_online_mode ( E_SHELL (object))); return; } @@ -202,10 +202,10 @@ shell_class_init (EShellClass *class) g_object_class_install_property ( object_class, - PROP_ONLINE, + PROP_ONLINE_MODE, g_param_spec_boolean ( - "online", - _("Online"), + "online-mode", + _("Online Mode"), _("Whether the shell is online"), TRUE, G_PARAM_READWRITE | @@ -290,9 +290,9 @@ e_shell_get_type (void) } EShell * -e_shell_new (gboolean online) +e_shell_new (gboolean online_mode) { - return g_object_new (E_TYPE_SHELL, "online", online, NULL); + return g_object_new (E_TYPE_SHELL, "online-mode", online_mode, NULL); } GtkWidget * @@ -349,22 +349,22 @@ e_shell_send_receive (EShell *shell, } gboolean -e_shell_get_online (EShell *shell) +e_shell_get_online_mode (EShell *shell) { g_return_val_if_fail (E_IS_SHELL (shell), FALSE); - return shell->priv->online; + return shell->priv->online_mode; } void -e_shell_set_online (EShell *shell, - gboolean online) +e_shell_set_online_mode (EShell *shell, + gboolean online_mode) { g_return_if_fail (E_IS_SHELL (shell)); - shell->priv->online = online; + shell->priv->online_mode = online_mode; - g_object_notify (G_OBJECT (shell), "online"); + g_object_notify (G_OBJECT (shell), "online-mode"); } EShellLineStatus diff --git a/shell/e-shell.h b/shell/e-shell.h index fd0e26e11b..a0f037ea98 100644 --- a/shell/e-shell.h +++ b/shell/e-shell.h @@ -49,7 +49,6 @@ typedef struct _EShellClass EShellClass; typedef struct _EShellPrivate EShellPrivate; typedef enum _EShellLineStatus EShellLineStatus; -typedef enum _EShellStartupLineMode EShellStartupLineMode; struct _EShell { GObject parent; @@ -67,12 +66,6 @@ enum _EShellLineStatus { E_SHELL_LINE_STATUS_FORCED_OFFLINE }; -enum _EShellStartupLineMode { - E_SHELL_STARTUP_LINE_MODE_CONFIG, - E_SHELL_STARTUP_LINE_MODE_ONLINE, - E_SHELL_STARTUP_LINE_MODE_OFFLINE -}; - GType e_shell_get_type (void); EShell * e_shell_new (gboolean online); GtkWidget * e_shell_create_window (EShell *shell); @@ -80,9 +73,9 @@ gboolean e_shell_handle_uri (EShell *shell, const gchar *uri); void e_shell_send_receive (EShell *shell, GtkWindow *parent); -gboolean e_shell_get_online (EShell *shell); -void e_shell_set_online (EShell *shell, - gboolean online); +gboolean e_shell_get_online_mode (EShell *shell); +void e_shell_set_online_mode (EShell *shell, + gboolean online_mode); EShellLineStatus e_shell_get_line_status (EShell *shell); void e_shell_set_line_status (EShell *shell, diff --git a/shell/main.c b/shell/main.c index 78fa80555f..292b7f96cf 100644 --- a/shell/main.c +++ b/shell/main.c @@ -282,23 +282,12 @@ open_uris (gchar **uris) static gboolean idle_cb (gchar **uris) { - EShellStartupLineMode startup_line_mode; - g_return_val_if_fail (uris == NULL || g_strv_length (uris) > 0, FALSE); #ifdef KILL_PROCESS_CMD kill_old_dataserver (); #endif - if (! start_online && ! start_offline) - startup_line_mode = E_SHELL_STARTUP_LINE_MODE_CONFIG; - else if (start_online) - startup_line_mode = E_SHELL_STARTUP_LINE_MODE_ONLINE; - else - startup_line_mode = E_SHELL_STARTUP_LINE_MODE_OFFLINE; - - /* FIXME Do something with startup_line_mode. */ - if (uris != NULL) open_uris (uris); else { @@ -486,16 +475,16 @@ create_shell (void) EShell *shell; GConfClient *conf_client; GnomeClient *master_client; - gboolean online = TRUE; + gboolean online_mode = TRUE; GError *error = NULL; conf_client = gconf_client_get_default (); master_client = gnome_master_client (); if (start_online) - online = TRUE; + online_mode = TRUE; else if (start_offline) - online = FALSE; + online_mode = FALSE; else { const gchar *key; gboolean value; @@ -503,14 +492,14 @@ create_shell (void) key = "/apps/evolution/shell/start_offline"; value = gconf_client_get_bool (conf_client, key, &error); if (error == NULL) - online = !value; + online_mode = !value; else { g_warning ("%s", error->message); g_error_free (error); } } - shell = e_shell_new (online); + shell = e_shell_new (online_mode); g_signal_connect ( shell, "window-destroyed", diff --git a/shell/test/e-test-shell-module.c b/shell/test/e-test-shell-module.c index 65c483bad0..f7deaaca67 100644 --- a/shell/test/e-test-shell-module.c +++ b/shell/test/e-test-shell-module.c @@ -18,6 +18,8 @@ * Boston, MA 02110-1301, USA. */ +#include <glib/gi18n.h> + #include <e-shell.h> #include <e-shell-module.h> #include <e-shell-window.h> @@ -32,6 +34,40 @@ /* Module Entry Point */ void e_shell_module_init (GTypeModule *module); +static void +action_new_test_item_cb (GtkAction *action, + EShellWindow *shell_window) +{ + g_debug ("%s", G_STRFUNC); +} + +static void +action_new_test_source_cb (GtkAction *action, + EShellWindow *shell_window) +{ + g_debug ("%s", G_STRFUNC); +} + +static GtkActionEntry item_entries[] = { + + { "new-test-item", + "document-new", + N_("_Test Item"), + NULL, + N_("Create a new test item"), + G_CALLBACK (action_new_test_item_cb) } +}; + +static GtkActionEntry source_entries[] = { + + { "new-test-source", + "folder-new", + N_("Test _Source"), + NULL, + N_("Create a new test source"), + G_CALLBACK (action_new_test_source_cb) } +}; + static gboolean test_module_is_busy (EShellModule *shell_module) { @@ -68,7 +104,19 @@ static void test_module_window_created (EShellModule *shell_module, EShellWindow *shell_window) { + const gchar *module_name; + g_debug ("%s (window=%p)", G_STRFUNC, shell_window); + + module_name = G_TYPE_MODULE (shell_module)->name; + + e_shell_window_register_new_item_actions ( + shell_window, module_name, + item_entries, G_N_ELEMENTS (item_entries)); + + e_shell_window_register_new_source_actions ( + shell_window, module_name, + source_entries, G_N_ELEMENTS (source_entries)); } static void diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am index 03f3e803ca..2365fe668d 100644 --- a/widgets/misc/Makefile.am +++ b/widgets/misc/Makefile.am @@ -47,7 +47,6 @@ widgetsinclude_HEADERS = \ e-cell-renderer-combo.h \ e-charset-picker.h \ e-combo-cell-editable.h \ - e-combo-button.h \ e-dateedit.h \ e-dropdown-button.h \ e-expander.h \ @@ -55,6 +54,7 @@ widgetsinclude_HEADERS = \ e-image-chooser.h \ e-info-label.h \ e-map.h \ + e-menu-tool-button.h \ e-preferences-window.h \ e-online-button.h \ e-search-bar.h \ @@ -94,7 +94,6 @@ libemiscwidgets_la_SOURCES = \ e-cell-renderer-combo.c \ e-charset-picker.c \ e-combo-cell-editable.c \ - e-combo-button.c \ e-dateedit.c \ e-dropdown-button.c \ e-expander.c \ @@ -102,6 +101,7 @@ libemiscwidgets_la_SOURCES = \ e-image-chooser.c \ e-info-label.c \ e-map.c \ + e-menu-tool-button.c \ e-preferences-window.c \ e-online-button.c \ e-search-bar.c \ diff --git a/widgets/misc/e-combo-button.c b/widgets/misc/e-combo-button.c deleted file mode 100644 index 6fc0fec57e..0000000000 --- a/widgets/misc/e-combo-button.c +++ /dev/null @@ -1,623 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-combo-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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-combo-button.h" -#include "ea-widgets.h" - -struct _EComboButtonPrivate { - GdkPixbuf *icon; - - GtkWidget *icon_image; - GtkWidget *label; - GtkWidget *arrow_image; - GtkWidget *hbox; - GtkWidget *vbox; - - GtkMenu *menu; - - gboolean menu_popped_up; - gboolean is_already_packed; -}; - -#define SPACING 2 - -enum { - ACTIVATE_DEFAULT, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -G_DEFINE_TYPE (EComboButton, e_combo_button, GTK_TYPE_BUTTON) - -/* Utility functions. */ - -static void -set_icon (EComboButton *combo_button, - GdkPixbuf *pixbuf) -{ - EComboButtonPrivate *priv; - - priv = combo_button->priv; - - if (priv->icon != NULL) - g_object_unref (priv->icon); - - if (pixbuf == NULL) { - priv->icon = NULL; - gtk_widget_hide (priv->icon_image); - return; - } - - priv->icon = g_object_ref (pixbuf); - - gtk_image_set_from_pixbuf (GTK_IMAGE (priv->icon_image), priv->icon); - - gtk_widget_show (priv->icon_image); -} - - -/* Paint the borders. */ - -static void -paint (EComboButton *combo_button, - GdkRectangle *area) -{ - EComboButtonPrivate *priv = combo_button->priv; - GtkWidget *widget = GTK_WIDGET (combo_button); - GtkButton *button = GTK_BUTTON (combo_button); - GtkShadowType shadow_type; - gboolean interior_focus; - int separator_x; - int focus_width, focus_pad; - int x, y, width, height; - int border_width; - - if (GTK_BUTTON (widget)->depressed || priv->menu_popped_up) { - shadow_type = GTK_SHADOW_IN; - gtk_widget_set_state (widget, GTK_STATE_ACTIVE); - } else if (GTK_BUTTON (widget)->relief == GTK_RELIEF_NONE && - (GTK_WIDGET_STATE (widget) == GTK_STATE_NORMAL || - GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)) - shadow_type = GTK_SHADOW_NONE; - else - shadow_type = GTK_SHADOW_OUT; - - border_width = GTK_CONTAINER (widget)->border_width; - - x = widget->allocation.x + border_width; - y = widget->allocation.y + border_width; - width = widget->allocation.width - border_width * 2; - height = widget->allocation.height - border_width * 2; - - separator_x = (priv->label->allocation.width - + priv->label->allocation.x - + priv->arrow_image->allocation.x) / 2; - - gtk_widget_style_get (GTK_WIDGET (widget), - "focus-line-width", &focus_width, - "focus-padding", &focus_pad, - "interior-focus", &interior_focus, - NULL); - - if (GTK_WIDGET_HAS_DEFAULT (widget) - && GTK_BUTTON (widget)->relief == GTK_RELIEF_NORMAL) - gtk_paint_box (widget->style, widget->window, - GTK_STATE_NORMAL, GTK_SHADOW_IN, - area, widget, "buttondefault", - x, y, width, height); - - if (!interior_focus && GTK_WIDGET_HAS_FOCUS (widget)) { - x += focus_width + focus_pad; - y += focus_width + focus_pad; - width -= 2 * (focus_width + focus_pad); - height -= 2 * (focus_width + focus_pad); - } - - if (button->relief != GTK_RELIEF_NONE || button->depressed || - priv->menu_popped_up || - GTK_WIDGET_STATE (widget) == GTK_STATE_PRELIGHT) { - - gtk_paint_box (widget->style, widget->window, - GTK_WIDGET_STATE (widget), shadow_type, - area, widget, "button", - x, y, separator_x, height); - - if (width - separator_x > 0) - gtk_paint_box (widget->style, widget->window, - GTK_WIDGET_STATE (widget), shadow_type, - area, widget, "button", - separator_x, y, width - separator_x, height); - } - - if (GTK_WIDGET_HAS_FOCUS (widget)) { - if (interior_focus) { - x += widget->style->xthickness + focus_pad; - y += widget->style->ythickness + focus_pad; - width -= 2 * (widget->style->xthickness + focus_pad); - height -= 2 * (widget->style->xthickness + focus_pad); - } else { - x -= focus_width + focus_pad; - y -= focus_width + focus_pad; - width += 2 * (focus_width + focus_pad); - height += 2 * (focus_width + focus_pad); - } - - gtk_paint_focus (widget->style, widget->window, - GTK_WIDGET_STATE (widget), - area, widget, "button", - x, y, width, height); - } -} - - -/* Callbacks for the associated menu. */ - -static void -menu_detacher (GtkWidget *widget, - GtkMenu *menu) -{ - EComboButton *combo_button; - EComboButtonPrivate *priv; - - combo_button = E_COMBO_BUTTON (widget); - priv = combo_button->priv; - g_signal_handlers_disconnect_matched (menu, - G_SIGNAL_MATCH_DATA, - 0, 0, NULL, NULL, - combo_button); - priv->menu = NULL; -} - -static void -menu_deactivate_callback (GtkMenuShell *menu_shell, - void *data) -{ - EComboButton *combo_button; - EComboButtonPrivate *priv; - - combo_button = E_COMBO_BUTTON (data); - priv = combo_button->priv; - - priv->menu_popped_up = FALSE; - - GTK_BUTTON (combo_button)->button_down = FALSE; - GTK_BUTTON (combo_button)->in_button = FALSE; - gtk_button_leave (GTK_BUTTON (combo_button)); - gtk_button_clicked (GTK_BUTTON (combo_button)); -} - -static void -menu_position_func (GtkMenu *menu, - gint *x_return, - gint *y_return, - gboolean *push_in, - void *data) -{ - EComboButton *combo_button; - GtkAllocation *allocation; - - combo_button = E_COMBO_BUTTON (data); - allocation = & (GTK_WIDGET (combo_button)->allocation); - - gdk_window_get_origin (GTK_WIDGET (combo_button)->window, x_return, y_return); - - *y_return += allocation->height; -} - - -/* GtkObject methods. */ - -static void -impl_destroy (GtkObject *object) -{ - EComboButton *combo_button; - EComboButtonPrivate *priv; - - combo_button = E_COMBO_BUTTON (object); - priv = combo_button->priv; - - if (priv) { - if (priv->arrow_image != NULL) { - gtk_widget_destroy (priv->arrow_image); - priv->arrow_image = NULL; - } - - if (priv->icon != NULL) { - g_object_unref (priv->icon); - priv->icon = NULL; - } - - g_free (priv); - combo_button->priv = NULL; - } - - (* GTK_OBJECT_CLASS (e_combo_button_parent_class)->destroy) (object); -} - - - -static gboolean -e_combo_button_popup (EComboButton *combo_button, GdkEventButton *event) -{ - EComboButtonPrivate *priv; - - g_return_val_if_fail (combo_button != NULL, FALSE); - g_return_val_if_fail (E_IS_COMBO_BUTTON (combo_button), FALSE); - - priv = combo_button->priv; - - priv->menu_popped_up = TRUE; - - if (event) - gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL, - menu_position_func, combo_button, - event->button, event->time); - else - gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL, - menu_position_func, combo_button, - 0, gtk_get_current_event_time()); - - return TRUE; -} -/* GtkWidget methods. */ - -static int -impl_button_press_event (GtkWidget *widget, - GdkEventButton *event) -{ - EComboButton *combo_button; - EComboButtonPrivate *priv; - - combo_button = E_COMBO_BUTTON (widget); - priv = combo_button->priv; - - if (event->type == GDK_BUTTON_PRESS && - (event->button == 1 || event->button == 3)) { - GTK_BUTTON (widget)->button_down = TRUE; - - if (event->button == 3 || - event->x >= priv->arrow_image->allocation.x) { - /* User clicked on the right side: pop up the menu. */ - gtk_button_pressed (GTK_BUTTON (widget)); - - e_combo_button_popup (combo_button, event); - } else { - /* User clicked on the left side: just behave like a - normal button (i.e. not a toggle). */ - gtk_button_pressed (GTK_BUTTON (widget)); - } - } - - return TRUE; -} - -static int -impl_leave_notify_event (GtkWidget *widget, - GdkEventCrossing *event) -{ - EComboButton *combo_button; - EComboButtonPrivate *priv; - - combo_button = E_COMBO_BUTTON (widget); - priv = combo_button->priv; - - /* This is to override the standard behavior of deactivating the button - when the pointer gets out of the widget, in the case in which we - have just popped up the menu. Otherwise, the button would look as - inactive when the menu is popped up. */ - if (! priv->menu_popped_up) - return (* GTK_WIDGET_CLASS (e_combo_button_parent_class)->leave_notify_event) (widget, event); - - return FALSE; -} - -static int -impl_expose_event (GtkWidget *widget, - GdkEventExpose *event) -{ - GtkBin *bin; - GdkEventExpose child_event; - - if (! GTK_WIDGET_DRAWABLE (widget)) - return FALSE; - - bin = GTK_BIN (widget); - - paint (E_COMBO_BUTTON (widget), &event->area); - - child_event = *event; - if (bin->child && GTK_WIDGET_NO_WINDOW (bin->child) && - gtk_widget_intersect (bin->child, &event->area, &child_event.area)) - gtk_container_propagate_expose (GTK_CONTAINER (widget), bin->child, &child_event); - - return FALSE; -} - - -/* GtkButton methods. */ - -static void -impl_released (GtkButton *button) -{ - EComboButton *combo_button; - EComboButtonPrivate *priv; - - combo_button = E_COMBO_BUTTON (button); - priv = combo_button->priv; - - /* Massive cut & paste from GtkButton here... The only change in - behavior here is that we want to emit ::activate_default when not - the menu hasn't been popped up. */ - - if (button->button_down) { - int new_state; - - button->button_down = FALSE; - - if (button->in_button) { - gtk_button_clicked (button); - - if (! priv->menu_popped_up) - g_signal_emit (button, signals[ACTIVATE_DEFAULT], 0); - } - - new_state = (button->in_button ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL); - - if (GTK_WIDGET_STATE (button) != new_state) { - gtk_widget_set_state (GTK_WIDGET (button), new_state); - - /* We _draw () instead of queue_draw so that if the - operation blocks, the label doesn't vanish. */ - /* XXX gtk_widget_draw() is deprecated. - * Replace it with GTK's implementation. */ - gtk_widget_queue_draw (GTK_WIDGET (button)); - gdk_window_process_updates ( - GTK_WIDGET (button)->window, TRUE); - } - } -} - - -static void -e_combo_button_class_init (EComboButtonClass *combo_button_class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkButtonClass *button_class; - - object_class = GTK_OBJECT_CLASS (combo_button_class); - object_class->destroy = impl_destroy; - - widget_class = GTK_WIDGET_CLASS (object_class); - widget_class->button_press_event = impl_button_press_event; - widget_class->leave_notify_event = impl_leave_notify_event; - widget_class->expose_event = impl_expose_event; - - button_class = GTK_BUTTON_CLASS (object_class); - button_class->released = impl_released; - - signals[ACTIVATE_DEFAULT] = g_signal_new ("activate_default", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (EComboButtonClass, activate_default), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - e_combo_button_a11y_init (); -} - -static void -e_combo_button_init (EComboButton *combo_button) -{ - EComboButtonPrivate *priv; - - priv = g_new (EComboButtonPrivate, 1); - combo_button->priv = priv; - - priv->icon = NULL; - priv->menu = NULL; - priv->menu_popped_up = FALSE; - priv->is_already_packed = FALSE; -} - -void -e_combo_button_pack_hbox (EComboButton *combo_button) -{ - EComboButtonPrivate *priv; - - priv = combo_button->priv; - - if(priv->is_already_packed){ - gtk_widget_destroy (priv->hbox); - } - - priv->hbox = gtk_hbox_new (FALSE, SPACING); - gtk_container_add (GTK_CONTAINER (combo_button), priv->hbox); - gtk_widget_show (priv->hbox); - - priv->icon_image = gtk_image_new_from_stock ( - GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_MENU); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->icon_image, TRUE, TRUE, 0); - gtk_widget_show (priv->icon_image); - - priv->label = gtk_label_new (""); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->label, TRUE, TRUE, - 0); - gtk_widget_show (priv->label); - - priv->arrow_image = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); - gtk_box_pack_end (GTK_BOX (priv->hbox), priv->arrow_image, TRUE, TRUE, - GTK_WIDGET (combo_button)->style->xthickness); - gtk_widget_show (priv->arrow_image); - - gtk_widget_show (priv->hbox); - - priv->is_already_packed = TRUE; -} - -void -e_combo_button_pack_vbox (EComboButton *combo_button) -{ - EComboButtonPrivate *priv; - - priv = combo_button->priv; - - if(priv->is_already_packed){ - gtk_widget_destroy (priv->hbox); - } - - priv->hbox = gtk_hbox_new (FALSE, SPACING); - gtk_container_add (GTK_CONTAINER (combo_button), priv->hbox); - gtk_widget_show (priv->hbox); - - priv->vbox = gtk_vbox_new (FALSE, 0); - gtk_widget_show (priv->vbox); - - priv->icon_image = gtk_image_new_from_stock ( - GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_MENU); - gtk_box_pack_start (GTK_BOX (priv->vbox), priv->icon_image, TRUE, TRUE, 0); - gtk_widget_show (priv->icon_image); - - priv->label = gtk_label_new (""); - gtk_box_pack_start (GTK_BOX (priv->vbox), priv->label, TRUE, TRUE, - 0); - gtk_widget_show (priv->label); - - gtk_box_pack_start (GTK_BOX(priv->hbox),priv->vbox, TRUE, TRUE, 0); - - priv->arrow_image = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); - gtk_box_pack_end (GTK_BOX (priv->hbox), priv->arrow_image, TRUE, TRUE, - GTK_WIDGET (combo_button)->style->xthickness); - gtk_widget_show (priv->arrow_image); - - gtk_widget_show (priv->hbox); - - priv->is_already_packed = TRUE; -} - - -void -e_combo_button_construct (EComboButton *combo_button) -{ - EComboButtonPrivate *priv; - - g_return_if_fail (combo_button != NULL); - g_return_if_fail (E_IS_COMBO_BUTTON (combo_button)); - - priv = combo_button->priv; - g_return_if_fail (priv->menu == NULL); - - GTK_WIDGET_UNSET_FLAGS (combo_button, GTK_CAN_FOCUS); - - gtk_button_set_relief (GTK_BUTTON (combo_button), GTK_RELIEF_NONE); -} - -GtkWidget * -e_combo_button_new (void) -{ - EComboButton *new; - - new = g_object_new (e_combo_button_get_type (), NULL); - e_combo_button_construct (new); - - return GTK_WIDGET (new); -} - - -void -e_combo_button_set_icon (EComboButton *combo_button, - GdkPixbuf *pixbuf) -{ - g_return_if_fail (combo_button != NULL); - g_return_if_fail (E_IS_COMBO_BUTTON (combo_button)); - - set_icon (combo_button, pixbuf); -} - -void -e_combo_button_set_label (EComboButton *combo_button, - const char *label) -{ - EComboButtonPrivate *priv; - - g_return_if_fail (combo_button != NULL); - g_return_if_fail (E_IS_COMBO_BUTTON (combo_button)); - - priv = combo_button->priv; - - if (label == NULL) - label = ""; - - gtk_label_parse_uline (GTK_LABEL (priv->label), label); -} - -void -e_combo_button_set_menu (EComboButton *combo_button, - GtkMenu *menu) -{ - EComboButtonPrivate *priv; - - g_return_if_fail (combo_button != NULL); - g_return_if_fail (E_IS_COMBO_BUTTON (combo_button)); - g_return_if_fail (menu != NULL); - g_return_if_fail (GTK_IS_MENU (menu)); - - priv = combo_button->priv; - - if (priv->menu != NULL) - gtk_menu_detach (priv->menu); - - priv->menu = menu; - if (menu == NULL) - return; - - gtk_menu_attach_to_widget (menu, GTK_WIDGET (combo_button), menu_detacher); - - g_signal_connect((menu), "deactivate", - G_CALLBACK (menu_deactivate_callback), - combo_button); -} - -GtkWidget * -e_combo_button_get_label (EComboButton *combo_button) -{ - EComboButtonPrivate *priv; - - g_return_val_if_fail (combo_button != NULL, NULL); - g_return_val_if_fail (E_IS_COMBO_BUTTON (combo_button), NULL); - - priv = combo_button->priv; - - return priv->label; -} - -gboolean -e_combo_button_popup_menu (EComboButton *combo_button) -{ - return e_combo_button_popup (combo_button, NULL); -} diff --git a/widgets/misc/e-combo-button.h b/widgets/misc/e-combo-button.h deleted file mode 100644 index 1167ff633d..0000000000 --- a/widgets/misc/e-combo-button.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-combo-button.h - * - * 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. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#ifndef _E_COMBO_BUTTON_H_ -#define _E_COMBO_BUTTON_H_ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#define E_TYPE_COMBO_BUTTON (e_combo_button_get_type ()) -#define E_COMBO_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_COMBO_BUTTON, EComboButton)) -#define E_COMBO_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_COMBO_BUTTON, EComboButtonClass)) -#define E_IS_COMBO_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_COMBO_BUTTON)) -#define E_IS_COMBO_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), E_TYPE_COMBO_BUTTON)) - - -typedef struct _EComboButton EComboButton; -typedef struct _EComboButtonPrivate EComboButtonPrivate; -typedef struct _EComboButtonClass EComboButtonClass; - -struct _EComboButton { - GtkButton parent; - - EComboButtonPrivate *priv; -}; - -struct _EComboButtonClass { - GtkButtonClass parent_class; - - /* Signals. */ - void (* activate_default) (EComboButton *combo_button); -}; - - -GType e_combo_button_get_type (void); -void e_combo_button_construct (EComboButton *combo_button); -GtkWidget *e_combo_button_new (void); - -void e_combo_button_set_icon (EComboButton *combo_button, - GdkPixbuf *pixbuf); -void e_combo_button_set_label (EComboButton *combo_button, - const char *label); -void e_combo_button_set_menu (EComboButton *combo_button, - GtkMenu *menu); -void e_combo_button_pack_vbox (EComboButton *combo_button); -void e_combo_button_pack_hbox (EComboButton *combo_button); - -GtkWidget *e_combo_button_get_label (EComboButton *combo_button); - -gboolean e_combo_button_popup_menu (EComboButton *combo_button); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_COMBO_BUTTON_H_ */ 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); +} diff --git a/widgets/misc/e-menu-tool-button.h b/widgets/misc/e-menu-tool-button.h new file mode 100644 index 0000000000..110c9af9d1 --- /dev/null +++ b/widgets/misc/e-menu-tool-button.h @@ -0,0 +1,67 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-menu-tool-button.h + * + * 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. + */ + +/* EMenuToolButton is a variation of GtkMenuToolButton where the + * button icon always reflects the first menu item, and clicking + * the button activates the first menu item. */ + +#ifndef E_MENU_TOOL_BUTTON_H +#define E_MENU_TOOL_BUTTON_H + +#include <gtk/gtk.h> + +/* Standard GObject macros */ +#define E_TYPE_MENU_TOOL_BUTTON \ + (e_menu_tool_button_get_type ()) +#define E_MENU_TOOL_BUTTON(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_MENU_TOOL_BUTTON, EMenuToolButton)) +#define E_MENU_TOOL_BUTTON_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_MENU_TOOL_BUTTON, EMenuToolButtonClass)) +#define E_IS_MENU_TOOL_BUTTON(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_MENU_TOOL_BUTTON)) +#define E_IS_MENU_TOOL_BUTTON_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_MENU_TOOL_BUTTON)) +#define E_MENU_TOOL_BUTTON_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_MENU_TOOL_BUTTON, EMenuToolButtonClass)) + +G_BEGIN_DECLS + +typedef struct _EMenuToolButton EMenuToolButton; +typedef struct _EMenuToolButtonClass EMenuToolButtonClass; + +struct _EMenuToolButton { + GtkMenuToolButton parent; +}; + +struct _EMenuToolButtonClass { + GtkMenuToolButtonClass parent_class; +}; + +GType e_menu_tool_button_get_type (void); +GtkToolItem * e_menu_tool_button_new (const gchar *label); + +G_END_DECLS + +#endif /* E_MENU_TOOL_BUTTON_H */ diff --git a/widgets/misc/e-preferences-window.c b/widgets/misc/e-preferences-window.c index 1f2d38345f..883d6df280 100644 --- a/widgets/misc/e-preferences-window.c +++ b/widgets/misc/e-preferences-window.c @@ -20,7 +20,7 @@ #include "e-preferences-window.h" -#include <libgnome/gnome-help.h> +#include <e-util/e-util.h> #define SWITCH_PAGE_INTERVAL 250 @@ -162,16 +162,9 @@ static void preferences_window_response (GtkDialog *dialog, gint response_id) { - GError *error = NULL; - switch (response_id) { case GTK_RESPONSE_HELP: - gnome_help_display ( - "evolution.xml", "config-prefs", &error); - if (error != NULL) { - g_warning ("%s", error->message); - g_error_free (error); - } + e_display_help (GTK_WINDOW (dialog), "config-prefs"); break; case GTK_RESPONSE_CLOSE: |