140670ac64e2b822a553aab7c2e0a3bedaa0da29
[claws.git] / src / gtk / menu.h
1 /*
2  * Sylpheed -- 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 #if !GTK_CHECK_VERSION(3, 0, 0)
26 #include "gtkcmoptionmenu.h"
27 #endif
28
29 #define MENU_VAL_ID "Claws::Menu::ValueID"
30 #define MENU_VAL_DATA "Claws::Menu::ValueDATA"
31
32 #define MENUITEM_ADD(menu, menuitem, label, data)                \
33 {                                                                \
34         if (label)                                               \
35                 menuitem = gtk_menu_item_new_with_label(label);  \
36         else {                                                   \
37                 menuitem = gtk_menu_item_new();                  \
38                 gtk_widget_set_sensitive(menuitem, FALSE);       \
39         }                                                        \
40         gtk_widget_show(menuitem);                               \
41         gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);   \
42         if (data)                                                \
43                 g_object_set_data(G_OBJECT(menuitem),            \
44                                   MENU_VAL_ID,                   \
45                                   GINT_TO_POINTER(data));        \
46 }
47
48 #define MENUITEM_ADDUI(path, name, action, type)                 \
49         gtk_ui_manager_add_ui(gtkut_ui_manager(),                \
50                         gtk_ui_manager_new_merge_id(gtkut_ui_manager()),\
51                         path, name, action, type, FALSE);
52
53 #define MENUITEM_ADDUI_MANAGER(ui_manager, path, name, action, type)    \
54         gtk_ui_manager_add_ui(ui_manager,                        \
55                         gtk_ui_manager_new_merge_id(ui_manager), \
56                         path, name, action, type, FALSE);
57
58 #define MENUITEM_ADDUI_ID(path, name, action, type,id)           \
59         id = gtk_ui_manager_new_merge_id(gtkut_ui_manager());    \
60         gtk_ui_manager_add_ui(gtkut_ui_manager(),                \
61                         id,                                      \
62                         path, name, action, type, FALSE);
63
64 #define MENUITEM_REMUI(action_group,name,id) {                  \
65         GtkAction *action = gtk_action_group_get_action(action_group, name); \
66         if (action) gtk_action_group_remove_action(action_group, action);       \
67         if (id) gtk_ui_manager_remove_ui(gtkut_ui_manager(), id);       \
68 }
69
70 #define MENUITEM_ADDUI_ID_MANAGER(manager,path,name,action,type,id)              \
71         id = gtk_ui_manager_new_merge_id(manager);       \
72         gtk_ui_manager_add_ui(manager,           \
73                         id,                                      \
74                         path, name, action, type, FALSE);
75
76 #define MENUITEM_REMUI_MANAGER(manager,action_group,name,id) {                  \
77         GtkAction *action = gtk_action_group_get_action(action_group, name); \
78         if (action) gtk_action_group_remove_action(action_group, action);       \
79         if (id) gtk_ui_manager_remove_ui(manager, id);  \
80 }
81
82 #define menu_set_insensitive_all(menu_shell) \
83         menu_set_sensitive_all(menu_shell, FALSE);
84
85 gchar *menu_translate           (const gchar *path, gpointer data);
86
87 GtkActionGroup *cm_menu_create_action_group(const gchar *name, GtkActionEntry *entries,
88                                             gint num_entries, gpointer data);
89 GtkActionGroup *cm_menu_create_action_group_full(GtkUIManager *ui_manager,
90                                             const gchar *name, GtkActionEntry *entries,
91                                             gint num_entries, gpointer data);
92 void cm_menu_set_sensitive(gchar *menu, gboolean sensitive);
93 void cm_toggle_menu_set_active(gchar *menu, gboolean active);
94 void cm_menu_set_sensitive_full(GtkUIManager *gui_manager, gchar *menu, gboolean sensitive);
95 void cm_toggle_menu_set_active_full(GtkUIManager *gui_manager, gchar *menu, gboolean active);
96
97 #if !GTK_CHECK_VERSION(3, 0, 0)
98 gint menu_find_option_menu_index(GtkCMOptionMenu *optmenu, gpointer data,
99                                  GCompareFunc func);
100 #endif
101
102 void menu_button_position       (GtkMenu                *menu,
103                                  gint                   *x,
104                                  gint                   *y,
105                                  gboolean               *push_in,
106                                  gpointer                user_data);
107
108 void menu_set_sensitive_all(GtkMenuShell *menu_shell, gboolean sensitive);
109
110 #endif /* __MENU_H__ */