7fda1aa2d76c7e4b2a456911b93ef9a7ab9aa759
[claws.git] / src / gtk / menu.h
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 Hiroyuki Yamamoto
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/gtkwidget.h>
25 #include <gtk/gtkitemfactory.h>
26 #include <gtk/gtkmenu.h>
27 #include <gtk/gtkmenushell.h>
28 #include <gtk/gtkoptionmenu.h>
29
30 #define MENU_VAL_ID "Claws::Menu::ValueID"
31 #define MENU_VAL_DATA "Claws::Menu::ValueDATA"
32
33 #define MENUITEM_ADD(menu, menuitem, label, data)                \
34 {                                                                \
35         if (label)                                               \
36                 menuitem = gtk_menu_item_new_with_label(label);  \
37         else {                                                   \
38                 menuitem = gtk_menu_item_new();                  \
39                 gtk_widget_set_sensitive(menuitem, FALSE);       \
40         }                                                        \
41         gtk_widget_show(menuitem);                               \
42         gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);   \
43         if (data)                                                \
44                 g_object_set_data(G_OBJECT(menuitem),            \
45                                   MENU_VAL_ID,                   \
46                                   GINT_TO_POINTER(data));        \
47 }
48
49 #define MENUITEM_ADDUI(path, name, action, type)                 \
50         gtk_ui_manager_add_ui(gtkut_ui_manager(),                \
51                         gtk_ui_manager_new_merge_id(gtkut_ui_manager()),\
52                         path, name, action, type, FALSE);
53
54 #define MENUITEM_ADDUI_ID(path, name, action, type,id)           \
55         id = gtk_ui_manager_new_merge_id(gtkut_ui_manager());    \
56         gtk_ui_manager_add_ui(gtkut_ui_manager(),                \
57                         id,                                      \
58                         path, name, action, type, FALSE);
59
60 #define MENUITEM_REMUI(action_group,name,id) {                  \
61         GtkAction *action = gtk_action_group_get_action(action_group, name); \
62         if (action) gtk_action_group_remove_action(action_group, action);       \
63         if (id) gtk_ui_manager_remove_ui(gtkut_ui_manager(), id);       \
64 }
65
66 #define menu_set_insensitive_all(menu_shell) \
67         menu_set_sensitive_all(menu_shell, FALSE);
68
69 GtkWidget *menubar_create       (GtkWidget              *window,
70                                  GtkItemFactoryEntry    *entries,
71                                  guint                   n_entries,
72                                  const gchar            *path,
73                                  gpointer                data);
74 GtkWidget *menu_create_items    (GtkItemFactoryEntry    *entries,
75                                  guint                   n_entries,
76                                  const gchar            *path,
77                                  GtkItemFactory        **factory,
78                                  gpointer                data);
79 gchar *menu_translate           (const gchar *path, gpointer data);
80
81 void menu_set_sensitive         (GtkItemFactory         *ifactory,
82                                  const gchar            *path,
83                                  gboolean                sensitive);
84
85 GtkActionGroup *cm_menu_create_action_group(const gchar *name, GtkActionEntry **entries,
86                                             gint num_entries, gpointer data);
87 void cm_menu_set_sensitive(gchar *menu, gboolean sensitive);
88 void cm_toggle_menu_set_active(gchar *menu, gboolean active);
89
90 void menu_set_active            (GtkItemFactory         *ifactory,
91                                  const gchar            *path,
92                                  gboolean                is_active);
93 void menu_button_position       (GtkMenu                *menu,
94                                  gint                   *x,
95                                  gint                   *y,
96                                  gboolean               *push_in,
97                                  gpointer                user_data);
98
99 gint menu_find_option_menu_index(GtkOptionMenu          *optmenu,
100                                  gpointer                data,
101                                  GCompareFunc            func);
102 void menu_set_sensitive_all(GtkMenuShell *menu_shell, gboolean sensitive);
103 void menu_connect_identical_items(void);
104
105 #endif /* __MENU_H__ */