More menu changes to facilitate plugins.
[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
7 #include <glib.h>
8
9 extern GHashTable *menu_map;
10
11 struct Menu;
12
13 typedef void(*menu_controller_show)(struct Menu *self, int x, int y, Client *);
14 typedef void(*menu_controller_update)(struct Menu *self);
15
16 typedef struct Menu {
17     char *label;
18     char *name;
19     
20     GList *entries;
21
22     gboolean shown;
23     gboolean invalid;
24
25     struct Menu *parent;
26
27     /* place a menu on screen */
28     menu_controller_show show;
29     void (*hide)( /* some bummu */);
30
31     /* render a menu */
32     menu_controller_update update;
33     void (*mouseover)( /* some bummu */);
34     void (*selected)( /* some bummu */);
35
36
37     /* render stuff */
38     Client *client;
39     Window frame;
40     Window title;
41     Appearance *a_title;
42     int title_min_w, title_h;
43     Window items;
44     Appearance *a_items;
45     int bullet_w;
46     int item_h;
47     int width;
48 } Menu;
49
50 typedef enum MenuEntryRenderType {
51     MenuEntryRenderType_None = 0,
52     MenuEntryRenderType_Submenu = 1 << 0,
53     MenuEntryRenderType_Boolean = 1 << 1,
54     MenuEntryRenderType_Separator = 1 << 2,
55     
56     MenuEntryRenderType_Other = 1 << 7
57 } MenuEntryRenderType;
58
59 typedef struct {
60     char *label;
61     Menu *parent;
62
63     Action *action;    
64     
65     MenuEntryRenderType render_type;
66     gboolean hilite;
67     gboolean enabled;
68     gboolean boolean_value;
69
70     Menu *submenu;
71
72     /* render stuff */
73     Window item;
74     Appearance *a_item;
75     Appearance *a_disabled;
76     Appearance *a_hilite;
77     int y;
78     int min_w;
79 } MenuEntry;
80
81 void menu_startup();
82 void menu_shutdown();
83
84 #define menu_new(l, n, p) \
85   menu_new_full(l, n, p, NULL, NULL)
86
87 Menu *menu_new_full(char *label, char *name, Menu *parent, 
88                     menu_controller_show show, menu_controller_update update);
89 void menu_free(char *name);
90
91 void menu_show(char *name, int x, int y, Client *client);
92 void menu_hide(Menu *self);
93
94 MenuEntry *menu_entry_new_full(char *label, Action *action,
95                                MenuEntryRenderType render_type,
96                                gpointer submenu);
97
98 #define menu_entry_new(label, action) \
99   menu_entry_new_full(label, action, MenuEntryRenderType_None, NULL)
100
101 void menu_entry_free(MenuEntry *entry);
102
103 void menu_entry_set_submenu(MenuEntry *entry, Menu *submenu);
104
105 void menu_add_entry(Menu *menu, MenuEntry *entry);
106
107 MenuEntry *menu_find_entry(Menu *menu, Window win);
108
109 void menu_entry_render(MenuEntry *self);
110
111 void menu_entry_fire(MenuEntry *self);
112
113 void menu_render(Menu *self);
114
115 #endif