]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/menu.h
rename the Client struct to ObClient
[mikachu/openbox.git] / openbox / menu.h
1 #ifndef __menu_h
2 #define __menu_h
3
4 #include "action.h"
5 #include "render/render.h"
6 #include "geom.h"
7
8 #include <glib.h>
9
10 struct Menu;
11 struct MenuEntry;
12
13 typedef void(*menu_controller_show)(struct Menu *self,
14                                     int x, int y, ObClient *);
15 typedef void(*menu_controller_update)(struct Menu *self);
16 typedef void(*menu_controller_mouseover)(struct MenuEntry *self,
17                                          gboolean enter);
18
19 extern GHashTable *menu_hash;
20 extern GSList *menu_visible;
21
22 typedef struct Menu {
23     ObWindow obwin;
24
25     char *label;
26     char *name;
27     
28     GList *entries;
29
30     gboolean shown;
31     gboolean invalid;
32
33     struct Menu *parent;
34     
35     struct Menu *open_submenu;
36
37     /* place a menu on screen */
38     menu_controller_show show;
39     void (*hide)( /* some bummu */);
40
41     /* render a menu */
42     menu_controller_update update;
43     menu_controller_mouseover mouseover;
44     void (*selected)( /* some bummu */);
45
46
47     /* render stuff */
48     ObClient *client;
49     Window frame;
50     Window title;
51     RrAppearance *a_title;
52     int title_min_w, title_h;
53     Window items;
54     RrAppearance *a_items;
55     int bullet_w;
56     int item_h;
57     Point location;
58     Size size;
59     guint xin_area; /* index of the xinerama head/area */
60
61     /* plugin stuff */
62     char *plugin;
63     void *plugin_data;
64 } Menu;
65
66 typedef enum MenuEntryRenderType {
67     MenuEntryRenderType_None = 0,
68     MenuEntryRenderType_Submenu = 1 << 0,
69     MenuEntryRenderType_Boolean = 1 << 1,
70     MenuEntryRenderType_Separator = 1 << 2,
71     
72     MenuEntryRenderType_Other = 1 << 7
73 } MenuEntryRenderType;
74
75 typedef struct MenuEntry {
76     char *label;
77     Menu *parent;
78
79     Action *action;    
80     
81     MenuEntryRenderType render_type;
82     gboolean hilite;
83     gboolean enabled;
84     gboolean boolean_value;
85
86     Menu *submenu;
87
88     /* render stuff */
89     Window item;
90     RrAppearance *a_item;
91     RrAppearance *a_disabled;
92     RrAppearance *a_hilite;
93     int y;
94     int min_w;
95 } MenuEntry;
96
97 void menu_startup();
98 void menu_shutdown();
99
100 #define menu_new(l, n, p) \
101   menu_new_full(l, n, p, NULL, NULL)
102
103 Menu *menu_new_full(char *label, char *name, Menu *parent, 
104                     menu_controller_show show, menu_controller_update update);
105 void menu_free(char *name);
106
107 void menu_show(char *name, int x, int y, ObClient *client);
108 void menu_show_full(Menu *menu, int x, int y, ObClient *client);
109
110 void menu_hide(Menu *self);
111
112 void menu_clear(Menu *self);
113
114 MenuEntry *menu_entry_new_full(char *label, Action *action,
115                                MenuEntryRenderType render_type,
116                                gpointer submenu);
117
118 #define menu_entry_new(label, action) \
119 menu_entry_new_full(label, action, MenuEntryRenderType_None, NULL)
120
121 #define menu_entry_new_separator(label) \
122 menu_entry_new_full(label, NULL, MenuEntryRenderType_Separator, NULL)
123
124 #define menu_entry_new_submenu(label, submenu) \
125 menu_entry_new_full(label, NULL, MenuEntryRenderType_Submenu, submenu)
126
127 #define menu_entry_new_boolean(label, action) \
128 menu_entry_new_full(label, action, MenuEntryRenderType_Boolean, NULL)
129
130 void menu_entry_free(MenuEntry *entry);
131
132 void menu_entry_set_submenu(MenuEntry *entry, Menu *submenu);
133
134 void menu_add_entry(Menu *menu, MenuEntry *entry);
135
136 MenuEntry *menu_find_entry(Menu *menu, Window win);
137 MenuEntry *menu_find_entry_by_pos(Menu *menu, int x, int y);
138
139 void menu_entry_render(MenuEntry *self);
140
141 void menu_entry_fire(MenuEntry *self);
142
143 void menu_render(Menu *self);
144 void menu_render_full(Menu *self);
145
146 void menu_control_mouseover(MenuEntry *entry, gboolean enter);
147 #endif