2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
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/>.
22 #include "claws-features.h"
26 #include <glib/gi18n.h>
29 #if !GTK_CHECK_VERSION(3, 0, 0)
30 #include "gtkcmoptionmenu.h"
38 #include <hildon/hildon-program.h>
40 #include <hildon-widgets/hildon-program.h>
44 GtkActionGroup *cm_menu_create_action_group(const gchar *name, GtkActionEntry *entries,
45 gint num_entries, gpointer data)
47 GtkActionGroup *group = gtk_action_group_new(name);
48 gtk_action_group_set_translate_func(group, menu_translate, NULL, NULL);
49 gtk_action_group_add_actions(group, entries, num_entries, data);
50 gtk_ui_manager_insert_action_group(gtkut_ui_manager(), group, 0);
54 GtkActionGroup *cm_menu_create_action_group_full(GtkUIManager *manager, const gchar *name, GtkActionEntry *entries,
55 gint num_entries, gpointer data)
57 GtkActionGroup *group = gtk_action_group_new(name);
58 gtk_action_group_set_translate_func(group, menu_translate, NULL, NULL);
59 gtk_action_group_add_actions(group, entries, num_entries, data);
60 gtk_ui_manager_insert_action_group(manager, group, 0);
64 gchar *menu_translate(const gchar *path, gpointer data)
68 retval = gettext(path);
73 void cm_menu_set_sensitive(gchar *menu, gboolean sensitive)
75 GtkUIManager *gui_manager = gtkut_ui_manager();
76 gchar *path = g_strdup_printf("Menus/%s", menu);
78 cm_menu_set_sensitive_full(gui_manager, path, sensitive);
82 void cm_toggle_menu_set_active(gchar *menu, gboolean active)
84 GtkUIManager *gui_manager = gtkut_ui_manager();
85 gchar *path = g_strdup_printf("Menus/%s", menu);
87 cm_toggle_menu_set_active_full(gui_manager, path, active);
91 void cm_menu_set_sensitive_full(GtkUIManager *gui_manager, gchar *menu, gboolean sensitive)
94 gchar *path = g_strdup_printf("/%s/", menu);
96 widget = gtk_ui_manager_get_widget(gui_manager, path);
97 if( !GTK_IS_WIDGET(widget) ) {
98 g_message("Blah, '%s' is not a widget.\n", path);
101 if( !GTK_IS_MENU_ITEM(widget) ) {
102 g_message("Blah, '%s' is not a menu item.\n", path);
105 gtk_widget_set_sensitive(widget, sensitive);
109 void cm_toggle_menu_set_active_full(GtkUIManager *gui_manager, gchar *menu, gboolean active)
112 gchar *path = g_strdup_printf("/%s/", menu);
114 widget = gtk_ui_manager_get_widget(gui_manager, path);
115 if( !GTK_IS_WIDGET(widget) ) {
116 g_message("Blah, '%s' is not a widget.\n", path);
119 if( !GTK_CHECK_MENU_ITEM(widget) ) {
120 g_message("Blah, '%s' is not a check menu item.\n", path);
123 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), active);
127 void menu_set_sensitive_all(GtkMenuShell *menu_shell, gboolean sensitive)
129 GList *children = gtk_container_get_children(GTK_CONTAINER(menu_shell));
132 for (cur = children; cur != NULL; cur = cur->next)
133 gtk_widget_set_sensitive(GTK_WIDGET(cur->data), sensitive);
135 g_list_free(children);
138 void menu_button_position(GtkMenu *menu, gint *x, gint *y, gboolean *push_in,
144 GtkAllocation allocation;
145 GtkRequisition mreq, wreq;
147 GdkRectangle monitor;
150 cm_return_if_fail(x && y);
151 cm_return_if_fail(GTK_IS_BUTTON(user_data));
153 widget = GTK_WIDGET(user_data);
155 gdk_window_get_origin(gtk_widget_get_window(widget), x, y);
156 gtk_widget_get_requisition(widget, &wreq);
157 wheight = wreq.height;
158 gtk_widget_get_allocation(widget, &allocation);
162 gtk_widget_size_request(GTK_WIDGET(menu), &mreq);
163 screen = gtk_widget_get_screen (widget);
164 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
165 gdk_screen_get_monitor_geometry (screen, monitor_num,
169 *y = *y + wy + wheight;
171 if (*y + mreq.height >= monitor.height)
175 #if !GTK_CHECK_VERSION(3, 0, 0)
176 gint menu_find_option_menu_index(GtkCMOptionMenu *optmenu, gpointer data,
186 menu = gtk_cmoption_menu_get_menu(optmenu);
187 children = gtk_container_get_children(GTK_CONTAINER(GTK_MENU_SHELL(menu)));
189 for (cur = children, n = 0;
190 cur != NULL; cur = cur->next, n++) {
191 menuitem = GTK_WIDGET(cur->data);
192 menu_data = g_object_get_data(G_OBJECT(menuitem),
195 if (func(menu_data, data) == 0)
197 } else if (menu_data == data)
201 g_list_free(children);