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>
43 static void connect_accel_change_signals(GtkWidget* widget, GtkWidget *wid2) ;
46 GtkActionGroup *cm_menu_create_action_group(const gchar *name, GtkActionEntry *entries,
47 gint num_entries, gpointer data)
49 GtkActionGroup *group = gtk_action_group_new(name);
50 gtk_action_group_set_translate_func(group, menu_translate, NULL, NULL);
51 gtk_action_group_add_actions(group, entries, num_entries, data);
52 gtk_ui_manager_insert_action_group(gtkut_ui_manager(), group, 0);
56 GtkActionGroup *cm_menu_create_action_group_full(GtkUIManager *manager, const gchar *name, GtkActionEntry *entries,
57 gint num_entries, gpointer data)
59 GtkActionGroup *group = gtk_action_group_new(name);
60 gtk_action_group_set_translate_func(group, menu_translate, NULL, NULL);
61 gtk_action_group_add_actions(group, entries, num_entries, data);
62 gtk_ui_manager_insert_action_group(manager, group, 0);
66 gchar *menu_translate(const gchar *path, gpointer data)
70 retval = gettext(path);
75 void cm_menu_set_sensitive(gchar *menu, gboolean sensitive)
77 GtkUIManager *gui_manager = gtkut_ui_manager();
78 gchar *path = g_strdup_printf("Menus/%s", menu);
80 cm_menu_set_sensitive_full(gui_manager, path, sensitive);
84 void cm_toggle_menu_set_active(gchar *menu, gboolean active)
86 GtkUIManager *gui_manager = gtkut_ui_manager();
87 gchar *path = g_strdup_printf("Menus/%s", menu);
89 cm_toggle_menu_set_active_full(gui_manager, path, active);
93 void cm_menu_set_sensitive_full(GtkUIManager *gui_manager, gchar *menu, gboolean sensitive)
96 gchar *path = g_strdup_printf("/%s/", menu);
98 widget = gtk_ui_manager_get_widget(gui_manager, path);
99 if( !GTK_IS_WIDGET(widget) ) {
100 g_message("Blah, '%s' is not a widget.\n", path);
103 if( !GTK_IS_MENU_ITEM(widget) ) {
104 g_message("Blah, '%s' is not a menu item.\n", path);
107 gtk_widget_set_sensitive(widget, sensitive);
111 void cm_toggle_menu_set_active_full(GtkUIManager *gui_manager, gchar *menu, gboolean active)
114 gchar *path = g_strdup_printf("/%s/", menu);
116 widget = gtk_ui_manager_get_widget(gui_manager, path);
117 if( !GTK_IS_WIDGET(widget) ) {
118 g_message("Blah, '%s' is not a widget.\n", path);
121 if( !GTK_CHECK_MENU_ITEM(widget) ) {
122 g_message("Blah, '%s' is not a check menu item.\n", path);
125 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), active);
129 void menu_set_sensitive_all(GtkMenuShell *menu_shell, gboolean sensitive)
133 for (cur = menu_shell->children; cur != NULL; cur = cur->next)
134 gtk_widget_set_sensitive(GTK_WIDGET(cur->data), sensitive);
137 void menu_button_position(GtkMenu *menu, gint *x, gint *y, gboolean *push_in,
145 GdkRectangle monitor;
148 g_return_if_fail(x && y);
149 g_return_if_fail(GTK_IS_BUTTON(user_data));
151 widget = GTK_WIDGET(user_data);
153 gdk_window_get_origin(widget->window, x, y);
154 wheight = widget->requisition.height;
155 wx = widget->allocation.x;
156 wy = widget->allocation.y;
158 gtk_widget_size_request(GTK_WIDGET(menu), &mreq);
159 screen = gtk_widget_get_screen (widget);
160 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
161 gdk_screen_get_monitor_geometry (screen, monitor_num,
165 *y = *y + wy + wheight;
167 if (*y + mreq.height >= monitor.height)
171 gint menu_find_option_menu_index(GtkCMOptionMenu *optmenu, gpointer data,
180 menu = gtk_cmoption_menu_get_menu(optmenu);
182 for (cur = GTK_MENU_SHELL(menu)->children, n = 0;
183 cur != NULL; cur = cur->next, n++) {
184 menuitem = GTK_WIDGET(cur->data);
185 menu_data = g_object_get_data(G_OBJECT(menuitem),
188 if (func(menu_data, data) == 0)
190 } else if (menu_data == data)
198 static void connect_accel_change_signals(GtkWidget* widget, GtkWidget *wid2)
200 g_signal_connect_after(G_OBJECT(widget), "add_accelerator",
201 G_CALLBACK(menu_item_add_accel), wid2);
202 g_signal_connect_after(G_OBJECT(widget), "remove_accelerator",
203 G_CALLBACK(menu_item_remove_accel), wid2);
207 void menu_connect_identical_items(void)
209 #if 0 /* DEPRECATED */
214 static const struct {
218 {"<Main>/Message/Reply", "<SummaryView>/Reply"},
220 {"<Main>/Message/Reply to/all", "<SummaryView>/Reply to/all"},
221 {"<Main>/Message/Reply to/sender", "<SummaryView>/Reply to/sender"},
222 {"<Main>/Message/Reply to/mailing list", "<SummaryView>/Reply to/mailing list"},
224 {"<Main>/Message/Forward", "<SummaryView>/Forward"},
226 {"<Main>/Message/Redirect", "<SummaryView>/Redirect"},
228 {"<Main>/Message/Move...", "<SummaryView>/Move..."},
229 {"<Main>/Message/Copy...", "<SummaryView>/Copy..."},
231 {"<Main>/Message/Delete...", "<SummaryView>/Delete..."},
233 {"<Main>/Message/Mark/Mark", "<SummaryView>/Mark/Mark"},
234 {"<Main>/Message/Mark/Unmark", "<SummaryView>/Mark/Unmark"},
235 {"<Main>/Message/Mark/Mark as unread", "<SummaryView>/Mark/Mark as unread"},
236 {"<Main>/Message/Mark/Mark as read", "<SummaryView>/Mark/Mark as read"},
237 {"<Main>/Message/Mark/Mark all read", "<SummaryView>/Mark/Mark all read"},
239 {"<Main>/Tools/Add sender to address book", "<SummaryView>/Add sender to address book"},
241 {"<Main>/Tools/Create filter rule/Automatically",
242 "<SummaryView>/Create filter rule/Automatically"},
243 {"<Main>/Tools/Create filter rule/by From", "<SummaryView>/Create filter rule/by From"},
244 {"<Main>/Tools/Create filter rule/by To", "<SummaryView>/Create filter rule/by To"},
245 {"<Main>/Tools/Create filter rule/by Subject", "<SummaryView>/Create filter rule/by Subject"},
247 {"<Main>/Tools/Create processing rule/Automatically",
248 "<SummaryView>/Create processing rule/Automatically"},
249 {"<Main>/Tools/Create processing rule/by From", "<SummaryView>/Create processing rule/by From"},
250 {"<Main>/Tools/Create processing rule/by To", "<SummaryView>/Create processing rule/by To"},
251 {"<Main>/Tools/Create processing rule/by Subject",
252 "<SummaryView>/Create processing rule/by Subject"},
254 {"<Main>/View/Open in new window", "<SummaryView>/View/Open in new window"},
255 {"<Main>/View/Message source", "<SummaryView>/View/Message source"},
257 {"<Main>/View/All headers", "<SummaryView>/View/All headers"},
261 const gint numpairs = sizeof pairs / sizeof pairs[0];
262 for (n = 0; n < numpairs; n++) {
263 /* get widgets from the paths */
265 item1 = gtk_item_factory_get_widget
266 (gtk_item_factory_from_path(pairs[n].path1),pairs[n].path1);
267 item2 = gtk_item_factory_get_widget
268 (gtk_item_factory_from_path(pairs[n].path2),pairs[n].path2);
270 if (item1 && item2) {
271 /* connect widgets both ways around */
272 connect_accel_change_signals(item2,item1);
273 connect_accel_change_signals(item1,item2);
275 if (!item1) debug_print(" ** Menu item not found: %s\n",pairs[n].path1);
276 if (!item2) debug_print(" ** Menu item not found: %s\n",pairs[n].path2);