]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/menu.h
make submenus not require the menu to exist when they are created, not until they...
[mikachu/openbox.git] / openbox / menu.h
1 #ifndef __menu_h
2 #define __menu_h
3
4 #include "action.h"
5 #include "window.h"
6 #include "geom.h"
7 #include "render/render.h"
8 #include "parser/parse.h"
9
10 #include <glib.h>
11
12 struct _ObClient;
13 struct _ObMenuFrame;
14 struct _ObMenuEntryFrame;
15
16 typedef struct _ObMenu ObMenu;
17 typedef struct _ObMenuEntry ObMenuEntry;
18 typedef struct _ObNormalMenuEntry ObNormalMenuEntry;
19 typedef struct _ObSubmenuMenuEntry ObSubmenuMenuEntry;
20 typedef struct _ObSeparatorMenuEntry ObSeparatorMenuEntry;
21
22 typedef void (*ObMenuUpdateFunc)(struct _ObMenuFrame *frame, gpointer data);
23 typedef void (*ObMenuExecuteFunc)(struct _ObMenuEntryFrame *frame,
24                                   gpointer data);
25 typedef void (*ObMenuDestroyFunc)(struct _ObMenu *menu, gpointer data);
26
27 extern GList *menu_visible;
28
29 struct _ObMenu
30 {
31     /* Name of the menu. Used in the showmenu action. */
32     gchar *name;
33     /* Displayed title */
34     gchar *title;
35
36     /* ObMenuEntry list */
37     GList *entries;
38
39     /* plugin data */
40     gpointer data;
41
42     ObMenuUpdateFunc update_func;
43     ObMenuExecuteFunc execute_func;
44     ObMenuDestroyFunc destroy_func;
45 };
46
47 typedef enum
48 {
49     OB_MENU_ENTRY_TYPE_NORMAL,
50     OB_MENU_ENTRY_TYPE_SUBMENU,
51     OB_MENU_ENTRY_TYPE_SEPARATOR
52 } ObMenuEntryType;
53
54 struct _ObNormalMenuEntry {
55     gchar *label;
56
57     /* state */
58     gboolean enabled;
59
60     /* List of ObActions */
61     GSList *actions;
62 };
63
64 struct _ObSubmenuMenuEntry {
65     gchar *name;
66     ObMenu *submenu;
67 };
68
69 struct _ObSeparatorMenuEntry {
70     gchar foo; /* placeholder */
71 };
72
73 struct _ObMenuEntry
74 {
75     ObMenuEntryType type;
76     ObMenu *menu;
77
78     gint id;
79
80     union u {
81         ObNormalMenuEntry normal;
82         ObSubmenuMenuEntry submenu;
83         ObSeparatorMenuEntry separator;
84     } data;
85 };
86
87 void menu_startup();
88 void menu_shutdown();
89
90 void menu_parse();
91
92 gboolean menu_new(gchar *name, gchar *title, gpointer data);
93 void menu_free(gchar *name);
94
95 gboolean menu_open_plugin(ObParseInst *i, gchar *name, gchar *plugin);
96
97 void menu_set_update_func(gchar *name, ObMenuUpdateFunc func);
98 void menu_set_execute_func(gchar *name, ObMenuExecuteFunc func);
99 void menu_set_destroy_func(gchar *name, ObMenuDestroyFunc func);
100
101 void menu_show(gchar *name, gint x, gint y, struct _ObClient *client);
102
103 /* functions for building menus */
104 void menu_clear_entries(gchar *name);
105 void menu_add_normal(gchar *name, gint id, gchar *label, GSList *actions);
106 void menu_add_submenu(gchar *name, gint id, gchar *submenu);
107 void menu_add_separator(gchar *name, gint id);
108
109 ObMenuEntry* menu_find_entry_id(ObMenu *self, gint id);
110
111 void menu_find_submenus(ObMenu *self);
112
113 #endif