1 /*
2  * GNT - The GLib Ncurses Toolkit
3  *
4  * GNT is the legal property of its developers, whose names are too numerous
5  * to list here.  Please refer to the COPYRIGHT file distributed with this
6  * source distribution.
7  *
8  * This library is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
21  */
22 
23 #ifndef GNT_MENU_H
24 #define GNT_MENU_H
25 /**
26  * SECTION:gntmenu
27  * @section_id: libgnt-gntmenu
28  * @title: GntMenu
29  * @short_description: A widget for a toplevel or popup menu
30  * @see_also: #GntMenuItem #GntMenuItemCheck
31  */
32 
33 #include "gnt.h"
34 #include "gnttree.h"
35 #include "gntcolors.h"
36 #include "gntkeys.h"
37 
38 #define GNT_TYPE_MENU				(gnt_menu_get_gtype())
39 #define GNT_MENU(obj)				(G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_MENU, GntMenu))
40 #define GNT_MENU_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_MENU, GntMenuClass))
41 #define GNT_IS_MENU(obj)			(G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_MENU))
42 #define GNT_IS_MENU_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_MENU))
43 #define GNT_MENU_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_MENU, GntMenuClass))
44 
45 #ifndef GNT_DISABLE_DEPRECATED
46 /**
47  * GNT_MENU_FLAGS:
48  *
49  * Deprecated: 2.14.0: This is an internal implementation detail.
50  */
51 #define GNT_MENU_FLAGS(obj)				(GNT_MENU(obj)->priv.flags)
52 /**
53  * GNT_MENU_SET_FLAGS:
54  *
55  * Deprecated: 2.14.0: This is an internal implementation detail.
56  */
57 #define GNT_MENU_SET_FLAGS(obj, flags)		(GNT_MENU_FLAGS(obj) |= flags)
58 /**
59  * GNT_MENU_UNSET_FLAGS:
60  *
61  * Deprecated: 2.14.0: This is an internal implementation detail.
62  */
63 #define GNT_MENU_UNSET_FLAGS(obj, flags)	(GNT_MENU_FLAGS(obj) &= ~(flags))
64 #endif
65 
66 typedef struct _GntMenu			GntMenu;
67 typedef struct _GntMenuClass		GntMenuClass;
68 #ifndef GNT_DISABLE_DEPRECATED
69 /**
70  * GntMenuPriv:
71  *
72  * Deprecated: 2.14.0: This is an internal implementation detail.
73  */
74 typedef struct _GntMenuPriv GntMenuPriv;
75 #endif
76 
77 #include "gntmenuitem.h"
78 
79 /**
80  * GntMenuType:
81  * @GNT_MENU_TOPLEVEL: Menu for a toplevel window
82  * @GNT_MENU_POPUP:    A popup menu
83  *
84  * A toplevel-menu is displayed at the top of the screen, and it spans accross
85  * the entire width of the screen.
86  * A popup-menu could be displayed, for example, as a context menu for widgets.
87  */
88 typedef enum
89 {
90 	GNT_MENU_TOPLEVEL = 1,
91 	GNT_MENU_POPUP,
92 } GntMenuType;
93 
94 /**
95  * GntMenu:
96  *
97  * Access to any fields is deprecated. See inline comments for replacements.
98  */
99 struct _GntMenu
100 {
101 	GntTree parent;
102 	GntMenuType GNTSEAL(type);
103 
104 	GList *GNTSEAL(list);
105 	int GNTSEAL(selected);
106 
107 	/* This will keep track of its immediate submenu which is visible so that
108 	 * keystrokes can be passed to it. */
109 	GntMenu *GNTSEAL(submenu);
110 	GntMenu *GNTSEAL(parentmenu);
111 };
112 
113 struct _GntMenuClass
114 {
115 	GntTreeClass parent;
116 
117 	/*< private >*/
118 	void (*gnt_reserved1)(void);
119 	void (*gnt_reserved2)(void);
120 	void (*gnt_reserved3)(void);
121 	void (*gnt_reserved4)(void);
122 };
123 
124 G_BEGIN_DECLS
125 
126 /**
127  * gnt_menu_get_gtype:
128  *
129  * Returns:  The GType for GntMenu.
130  */
131 GType gnt_menu_get_gtype(void);
132 
133 /**
134  * gnt_menu_new:
135  * @type:  The type of the menu, whether it's a toplevel menu or a popup menu.
136  *
137  * Create a new menu.
138  *
139  * Returns:  The newly created menu.
140  */
141 GntWidget * gnt_menu_new(GntMenuType type);
142 
143 /**
144  * gnt_menu_add_item:
145  * @menu:   The menu.
146  * @item:   The item to add to the menu.
147  *
148  * Add an item to the menu.
149  */
150 void gnt_menu_add_item(GntMenu *menu, GntMenuItem *item);
151 
152 /**
153  * gnt_menu_get_item:
154  * @menu:   The menu.
155  * @id:     The ID for an item.
156  *
157  * Return the GntMenuItem with the given ID.
158  *
159  * Returns: (transfer none): The menuitem with the given ID, or %NULL.
160  *
161  * Since: 2.3.0
162  */
163 GntMenuItem *gnt_menu_get_item(GntMenu *menu, const char *id);
164 
165 G_END_DECLS
166 
167 #endif /* GNT_MENU_H */
168