]> Dogcows Code - chaz/openbox/blob - openbox/menu.h
1adac022e10e12d2e97992cd6eafc8a81fe2ebd1
[chaz/openbox] / openbox / menu.h
1 #ifndef __menu_h
2 #define __menu_h
3
4 #include "action.h"
5 #include "window.h"
6 #include "render/render.h"
7 #include "geom.h"
8
9 #include <glib.h>
10
11 struct _ObClient;
12 struct _ObParseInst;
13
14 typedef struct _ObMenu ObMenu;
15 typedef struct _ObMenuEntry ObMenuEntry;
16
17 typedef void(*menu_controller_show)(ObMenu *self, int x, int y,
18 struct _ObClient *);
19 typedef void(*menu_controller_update)(ObMenu *self);
20 typedef void(*menu_controller_mouseover)(ObMenuEntry *self, gboolean enter);
21 typedef void(*menu_controller_selected)(ObMenuEntry *entry,
22 unsigned int button,
23 unsigned int x, unsigned int y);
24 typedef void(*menu_controller_hide)(ObMenu *self);
25
26
27 extern GHashTable *menu_hash;
28 extern GList *menu_visible;
29
30 struct _ObMenu
31 {
32 ObWindow obwin;
33
34 /* The title displayed above the menu.
35 NULL for no titlebar */
36 gchar *label;
37
38 /* Name of the menu.
39 Used in the action showmenu */
40 gchar *name;
41
42 /* ObMenuEntry list */
43 GList *entries;
44
45 /* If the menu is currently displayed */
46 gboolean shown;
47
48 /* If the rendering of the menu has changed and needs to be rerendered. */
49 gboolean invalid;
50
51 /* Kind of lame.Each menu can only be a submenu, and each menu can only
52 have one submenu open */
53 ObMenu *parent;
54 ObMenu *open_submenu;
55 GList *over;
56
57 /* behaviour callbacks
58 TODO: Document and split code that HAS to be in the overridden callback */
59 /* place a menu on screen */
60 menu_controller_show show;
61 /* Hide the menu */
62 menu_controller_hide hide;
63 /* render a menu */
64 menu_controller_update update;
65 /* Event for a mouse enter/exit on an entry
66 TODO: May have to split from simple render updating?
67 */
68 menu_controller_mouseover mouseover;
69 /* Entry is clicked/hit enter on */
70 menu_controller_selected selected;
71
72
73 /* render stuff */
74 struct _ObClient *client;
75 Window frame;
76 Window title;
77 RrAppearance *a_title;
78 gint title_min_w, title_h;
79 Window items;
80 RrAppearance *a_items;
81 gint bullet_w;
82 gint item_h;
83 Point location;
84 Size size;
85 guint xin_area; /* index of the xinerama head/area */
86
87 /* Name of plugin for menu */
88 char *plugin;
89 /* plugin's data */
90 void *plugin_data;
91 };
92
93 typedef enum
94 {
95 OB_MENU_ENTRY_RENDER_TYPE_NONE,
96 OB_MENU_ENTRY_RENDER_TYPE_SUBMENU,
97 OB_MENU_ENTRY_RENDER_TYPE_BOOLEAN,
98 OB_MENU_ENTRY_RENDER_TYPE_SEPARATOR,
99 OB_MENU_ENTRY_RENDER_TYPE_OTHER /* XXX what is this? */
100 } ObMenuEntryRenderType;
101
102 struct _ObMenuEntry
103 {
104 char *label;
105 ObMenu *parent;
106
107 ObAction *action;
108
109 ObMenuEntryRenderType render_type;
110 gboolean hilite;
111 gboolean enabled;
112 gboolean boolean_value;
113
114 ObMenu *submenu;
115
116 /* render stuff */
117 Window item;
118 Window submenu_pic;
119
120 RrAppearance *a_item;
121 RrAppearance *a_disabled;
122 RrAppearance *a_hilite;
123 RrAppearance *a_submenu;
124 gint y;
125 gint min_w;
126 } MenuEntry;
127
128 typedef struct PluginMenuCreateData{
129 struct _ObParseInst *parse_inst;
130 xmlDocPtr doc;
131 xmlNodePtr node;
132 ObMenu *parent;
133 } PluginMenuCreateData;
134
135
136 void menu_startup();
137 void menu_shutdown();
138
139 void menu_parse();
140
141 void menu_noop();
142
143 #define menu_new(l, n, p) \
144 menu_new_full(l, n, p, menu_show_full, menu_render, menu_entry_fire, \
145 menu_hide, menu_control_mouseover)
146
147 ObMenu *menu_new_full(char *label, char *name, ObMenu *parent,
148 menu_controller_show show, menu_controller_update update,
149 menu_controller_selected selected,
150 menu_controller_hide hide,
151 menu_controller_mouseover mouseover);
152
153 void menu_free(char *name);
154
155 void menu_show(char *name, int x, int y, struct _ObClient *client);
156 void menu_show_full(ObMenu *menu, int x, int y, struct _ObClient *client);
157
158 void menu_hide(ObMenu *self);
159
160 void menu_clear(ObMenu *self);
161
162 ObMenuEntry *menu_entry_new_full(char *label, ObAction *action,
163 ObMenuEntryRenderType render_type,
164 gpointer submenu);
165
166 #define menu_entry_new(label, action) \
167 menu_entry_new_full(label, action, OB_MENU_ENTRY_RENDER_TYPE_NONE, NULL)
168
169 #define menu_entry_new_separator(label) \
170 menu_entry_new_full(label, NULL, OB_MENU_ENTRY_RENDER_TYPE_SEPARATOR, NULL)
171
172 #define menu_entry_new_submenu(label, submenu) \
173 menu_entry_new_full(label, NULL, OB_MENU_ENTRY_RENDER_TYPE_SUBMENU, submenu)
174
175 #define menu_entry_new_boolean(label, action) \
176 menu_entry_new_full(label, action, OB_MENU_ENTRY_RENDER_TYPE_BOOLEAN, NULL)
177
178 void menu_entry_free(ObMenuEntry *entry);
179
180 void menu_entry_set_submenu(ObMenuEntry *entry, ObMenu *submenu);
181
182 void menu_add_entry(ObMenu *menu, ObMenuEntry *entry);
183
184 ObMenuEntry *menu_find_entry(ObMenu *menu, Window win);
185 ObMenuEntry *menu_find_entry_by_submenu(ObMenu *menu, ObMenu *submenu);
186 ObMenuEntry *menu_find_entry_by_pos(ObMenu *menu, int x, int y);
187
188 void menu_entry_render(ObMenuEntry *self);
189
190 void menu_entry_fire(ObMenuEntry *entry,
191 unsigned int button, unsigned int x, unsigned int y);
192
193 void menu_render(ObMenu *self);
194 void menu_render_full(ObMenu *self);
195
196 /*so plugins can call it? */
197 void parse_menu_full(struct _ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
198 void *data, gboolean new);
199 void menu_control_mouseover(ObMenuEntry *entry, gboolean enter);
200 void menu_control_keyboard_nav(unsigned int key);
201 #endif
This page took 0.046897 seconds and 4 git commands to generate.