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