2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2007 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include <glib/gi18n.h>
28 #include "gtkcmoptionmenu.h"
35 #include <hildon/hildon-program.h>
37 #include <hildon-widgets/hildon-program.h>
39 #include <gtk/gtkmain.h>
42 static void connect_accel_change_signals(GtkWidget* widget, GtkWidget *wid2) ;
45 GtkActionGroup *cm_menu_create_action_group(const gchar *name, GtkActionEntry *entries,
46 gint num_entries, gpointer data)
48 GtkActionGroup *group = gtk_action_group_new(name);
49 gtk_action_group_set_translate_func(group, menu_translate, NULL, NULL);
50 gtk_action_group_add_actions(group, entries, num_entries, data);
51 gtk_ui_manager_insert_action_group(gtkut_ui_manager(), group, 0);
55 GtkActionGroup *cm_menu_create_action_group_full(GtkUIManager *manager, const gchar *name, GtkActionEntry *entries,
56 gint num_entries, gpointer data)
58 GtkActionGroup *group = gtk_action_group_new(name);
59 gtk_action_group_set_translate_func(group, menu_translate, NULL, NULL);
60 gtk_action_group_add_actions(group, entries, num_entries, data);
61 gtk_ui_manager_insert_action_group(manager, group, 0);
65 gchar *menu_translate(const gchar *path, gpointer data)
69 retval = gettext(path);
74 void cm_menu_set_sensitive(gchar *menu, gboolean sensitive)
76 GtkUIManager *gui_manager = gtkut_ui_manager();
77 gchar *path = g_strdup_printf("Menus/%s", menu);
79 cm_menu_set_sensitive_full(gui_manager, path, sensitive);
83 void cm_toggle_menu_set_active(gchar *menu, gboolean active)
85 GtkUIManager *gui_manager = gtkut_ui_manager();
86 gchar *path = g_strdup_printf("Menus/%s", menu);
88 cm_toggle_menu_set_active_full(gui_manager, path, active);
92 void cm_menu_set_sensitive_full(GtkUIManager *gui_manager, gchar *menu, gboolean sensitive)
95 gchar *path = g_strdup_printf("/%s/", menu);
97 widget = gtk_ui_manager_get_widget(gui_manager, path);
98 if( !GTK_IS_WIDGET(widget) ) {
99 g_message("Blah, '%s' is not a widget.\n", path);
102 if( !GTK_IS_MENU_ITEM(widget) ) {
103 g_message("Blah, '%s' is not a menu item.\n", path);
106 gtk_widget_set_sensitive(widget, sensitive);
110 void cm_toggle_menu_set_active_full(GtkUIManager *gui_manager, gchar *menu, gboolean active)
113 gchar *path = g_strdup_printf("/%s/", menu);
115 widget = gtk_ui_manager_get_widget(gui_manager, path);
116 if( !GTK_IS_WIDGET(widget) ) {
117 g_message("Blah, '%s' is not a widget.\n", path);
120 if( !GTK_CHECK_MENU_ITEM(widget) ) {
121 g_message("Blah, '%s' is not a check menu item.\n", path);
124 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), active);
128 void menu_set_sensitive_all(GtkMenuShell *menu_shell, gboolean sensitive)
132 for (cur = menu_shell->children; cur != NULL; cur = cur->next)
133 gtk_widget_set_sensitive(GTK_WIDGET(cur->data), sensitive);
136 void menu_button_position(GtkMenu *menu, gint *x, gint *y, gboolean *push_in,
144 GdkRectangle monitor;
147 g_return_if_fail(x && y);
148 g_return_if_fail(GTK_IS_BUTTON(user_data));
150 widget = GTK_WIDGET(user_data);
152 gdk_window_get_origin(widget->window, x, y);
153 wheight = widget->requisition.height;
154 wx = widget->allocation.x;
155 wy = widget->allocation.y;
157 gtk_widget_size_request(GTK_WIDGET(menu), &mreq);
158 screen = gtk_widget_get_screen (widget);
159 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
160 gdk_screen_get_monitor_geometry (screen, monitor_num,
164 *y = *y + wy + wheight;
166 if (*y + mreq.height >= monitor.height)
170 gint menu_find_option_menu_index(GtkCMOptionMenu *optmenu, gpointer data,
179 menu = gtk_cmoption_menu_get_menu(optmenu);
181 for (cur = GTK_MENU_SHELL(menu)->children, n = 0;
182 cur != NULL; cur = cur->next, n++) {
183 menuitem = GTK_WIDGET(cur->data);
184 menu_data = g_object_get_data(G_OBJECT(menuitem),
187 if (func(menu_data, data) == 0)
189 } else if (menu_data == data)
196 static void connect_accel_change_signals(GtkWidget* widget, GtkWidget *wid2)
199 g_signal_connect_after(G_OBJECT(widget), "add_accelerator",
200 G_CALLBACK(menu_item_add_accel), wid2);
201 g_signal_connect_after(G_OBJECT(widget), "remove_accelerator",
202 G_CALLBACK(menu_item_remove_accel), wid2);
206 void menu_connect_identical_items(void)
208 #if 0 /* DEPRECATED */
213 static const struct {
217 {"<Main>/Message/Reply", "<SummaryView>/Reply"},
219 {"<Main>/Message/Reply to/all", "<SummaryView>/Reply to/all"},
220 {"<Main>/Message/Reply to/sender", "<SummaryView>/Reply to/sender"},
221 {"<Main>/Message/Reply to/mailing list", "<SummaryView>/Reply to/mailing list"},
223 {"<Main>/Message/Forward", "<SummaryView>/Forward"},
225 {"<Main>/Message/Redirect", "<SummaryView>/Redirect"},
227 {"<Main>/Message/Move...", "<SummaryView>/Move..."},
228 {"<Main>/Message/Copy...", "<SummaryView>/Copy..."},
230 {"<Main>/Message/Delete...", "<SummaryView>/Delete..."},
232 {"<Main>/Message/Mark/Mark", "<SummaryView>/Mark/Mark"},
233 {"<Main>/Message/Mark/Unmark", "<SummaryView>/Mark/Unmark"},
234 {"<Main>/Message/Mark/Mark as unread", "<SummaryView>/Mark/Mark as unread"},
235 {"<Main>/Message/Mark/Mark as read", "<SummaryView>/Mark/Mark as read"},
236 {"<Main>/Message/Mark/Mark all read", "<SummaryView>/Mark/Mark all read"},
238 {"<Main>/Tools/Add sender to address book", "<SummaryView>/Add sender to address book"},
240 {"<Main>/Tools/Create filter rule/Automatically",
241 "<SummaryView>/Create filter rule/Automatically"},
242 {"<Main>/Tools/Create filter rule/by From", "<SummaryView>/Create filter rule/by From"},
243 {"<Main>/Tools/Create filter rule/by To", "<SummaryView>/Create filter rule/by To"},
244 {"<Main>/Tools/Create filter rule/by Subject", "<SummaryView>/Create filter rule/by Subject"},
246 {"<Main>/Tools/Create processing rule/Automatically",
247 "<SummaryView>/Create processing rule/Automatically"},
248 {"<Main>/Tools/Create processing rule/by From", "<SummaryView>/Create processing rule/by From"},
249 {"<Main>/Tools/Create processing rule/by To", "<SummaryView>/Create processing rule/by To"},
250 {"<Main>/Tools/Create processing rule/by Subject",
251 "<SummaryView>/Create processing rule/by Subject"},
253 {"<Main>/View/Open in new window", "<SummaryView>/View/Open in new window"},
254 {"<Main>/View/Message source", "<SummaryView>/View/Message source"},
256 {"<Main>/View/All headers", "<SummaryView>/View/All headers"},
260 const gint numpairs = sizeof pairs / sizeof pairs[0];
261 for (n = 0; n < numpairs; n++) {
262 /* get widgets from the paths */
264 item1 = gtk_item_factory_get_widget
265 (gtk_item_factory_from_path(pairs[n].path1),pairs[n].path1);
266 item2 = gtk_item_factory_get_widget
267 (gtk_item_factory_from_path(pairs[n].path2),pairs[n].path2);
269 if (item1 && item2) {
270 /* connect widgets both ways around */
271 connect_accel_change_signals(item2,item1);
272 connect_accel_change_signals(item1,item2);
274 if (!item1) debug_print(" ** Menu item not found: %s\n",pairs[n].path1);
275 if (!item2) debug_print(" ** Menu item not found: %s\n",pairs[n].path2);