fix CID 1596595: Resource leaks, and CID 1596594: (CHECKED_RETURN)
[claws.git] / src / gtk / menu.h
1 /*
2  * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
4  *
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.
9  *
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.
14  *
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/>.
17  * 
18  */
19
20 #ifndef __MENU_H__
21 #define __MENU_H__
22
23 #include <glib.h>
24 #include <gtk/gtk.h>
25
26 #define MENU_VAL_ID "Claws::Menu::ValueID"
27 #define MENU_VAL_DATA "Claws::Menu::ValueDATA"
28
29 #define MENUITEM_ADD(menu, menuitem, label, data)                \
30 {                                                                \
31         if (label)                                               \
32                 menuitem = gtk_menu_item_new_with_label(label);  \
33         else {                                                   \
34                 menuitem = gtk_menu_item_new();                  \
35                 gtk_widget_set_sensitive(menuitem, FALSE);       \
36         }                                                        \
37         gtk_widget_show(menuitem);                               \
38         gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);   \
39         if (data)                                                \
40                 g_object_set_data(G_OBJECT(menuitem),            \
41                                   MENU_VAL_ID,                   \
42                                   GINT_TO_POINTER(data));        \
43 }
44
45 #define MENUITEM_ADDUI(path, name, action, type)                 \
46         gtk_ui_manager_add_ui(gtkut_ui_manager(),                \
47                         gtk_ui_manager_new_merge_id(gtkut_ui_manager()),\
48                         path, name, action, type, FALSE);
49
50 #define MENUITEM_ADDUI_MANAGER(ui_manager, path, name, action, type)    \
51         gtk_ui_manager_add_ui(ui_manager,                        \
52                         gtk_ui_manager_new_merge_id(ui_manager), \
53                         path, name, action, type, FALSE);
54
55 #define MENUITEM_ADDUI_ID(path, name, action, type,id)           \
56         id = gtk_ui_manager_new_merge_id(gtkut_ui_manager());    \
57         gtk_ui_manager_add_ui(gtkut_ui_manager(),                \
58                         id,                                      \
59                         path, name, action, type, FALSE);
60
61 #define MENUITEM_REMUI(action_group,name,id) {                  \
62         GtkAction *action = gtk_action_group_get_action(action_group, name); \
63         if (action) gtk_action_group_remove_action(action_group, action);       \
64         if (id) gtk_ui_manager_remove_ui(gtkut_ui_manager(), id);       \
65 }
66
67 #define MENUITEM_ADDUI_ID_MANAGER(manager,path,name,action,type,id)              \
68         id = gtk_ui_manager_new_merge_id(manager);       \
69         gtk_ui_manager_add_ui(manager,           \
70                         id,                                      \
71                         path, name, action, type, FALSE);
72
73 #define MENUITEM_REMUI_MANAGER(manager,action_group,name,id) {                  \
74         GtkAction *action = gtk_action_group_get_action(action_group, name); \
75         if (action) gtk_action_group_remove_action(action_group, action);       \
76         if (id) gtk_ui_manager_remove_ui(manager, id);  \
77 }
78
79 #define menu_set_insensitive_all(menu_shell) \
80         menu_set_sensitive_all(menu_shell, FALSE);
81
82 gchar *menu_translate           (const gchar *path, gpointer data);
83
84 GtkActionGroup *cm_menu_create_action_group(const gchar *name, GtkActionEntry *entries,
85                                             gint num_entries, gpointer data);
86 GtkActionGroup *cm_menu_create_action_group_full(GtkUIManager *ui_manager,
87                                             const gchar *name, GtkActionEntry *entries,
88                                             gint num_entries, gpointer data);
89 void cm_menu_set_sensitive(gchar *menu, gboolean sensitive);
90 void cm_toggle_menu_set_active(gchar *menu, gboolean active);
91 void cm_menu_set_sensitive_full(GtkUIManager *gui_manager, const gchar *menu, gboolean sensitive);
92 void cm_toggle_menu_set_active_full(GtkUIManager *gui_manager, gchar *menu, gboolean active);
93 gchar *cm_menu_item_get_shortcut(GtkUIManager *gui_manager, gchar *menu);
94 GtkWidget *cm_menu_item_new_label_from_url(gchar *label);
95
96 void menu_set_sensitive_all(GtkMenuShell *menu_shell, gboolean sensitive);
97
98 #endif /* __MENU_H__ */