]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/menu.h
action.h not needed here
[mikachu/openbox.git] / openbox / menu.h
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    menu.h for the Openbox window manager
4    Copyright (c) 2003-2007   Dana Jansens
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #ifndef __menu_h
20 #define __menu_h
21
22 #include "window.h"
23 #include "geom.h"
24 #include "render/render.h"
25 #include "parser/parse.h"
26
27 #include <glib.h>
28
29 struct _ObClient;
30 struct _ObMenuFrame;
31 struct _ObMenuEntryFrame;
32
33 typedef struct _ObMenu ObMenu;
34 typedef struct _ObMenuEntry ObMenuEntry;
35 typedef struct _ObNormalMenuEntry ObNormalMenuEntry;
36 typedef struct _ObSubmenuMenuEntry ObSubmenuMenuEntry;
37 typedef struct _ObSeparatorMenuEntry ObSeparatorMenuEntry;
38
39 typedef void (*ObMenuShowFunc)(struct _ObMenuFrame *frame, gpointer data);
40 typedef void (*ObMenuHideFunc)(struct _ObMenuFrame *frame, gpointer data);
41 typedef gboolean (*ObMenuUpdateFunc)(struct _ObMenuFrame *frame,
42                                      gpointer data);
43 typedef void (*ObMenuExecuteFunc)(struct _ObMenuEntry *entry,
44                                   struct _ObMenuFrame *frame,
45                                   struct _ObClient *client,
46                                   guint state, gpointer data);
47 typedef void (*ObMenuDestroyFunc)(struct _ObMenu *menu, gpointer data);
48 /*! @param x is the mouse x coordinate. on return it should be the x coordinate
49              for the menu
50     @param y is the mouse y coordinate. on return it should be the y coordinate
51              for the menu
52 */
53 typedef void (*ObMenuPlaceFunc)(struct _ObMenuFrame *frame, gint *x, gint *y,
54                                 gboolean mouse, gpointer data);
55
56 struct _ObMenu
57 {
58     /* Name of the menu. Used in the showmenu action. */
59     gchar *name;
60     /* Displayed title */
61     gchar *title;
62     /*! The shortcut key that would be used to activate this menu if it was
63       displayed as a submenu */
64     gunichar shortcut;
65     /*! The shortcut's position in the string */
66     guint shortcut_position;
67
68     /*! If the shortcut key should be shown in menu entries even when it
69       is the first character in the string */
70     gboolean show_all_shortcuts;
71
72     /* Command to execute to rebuild the menu */
73     gchar *execute;
74
75     /* ObMenuEntry list */
76     GList *entries;
77
78     /* plugin data */
79     gpointer data;
80
81     ObMenuShowFunc show_func;
82     ObMenuHideFunc hide_func;
83     ObMenuUpdateFunc update_func;
84     ObMenuExecuteFunc execute_func;
85     ObMenuDestroyFunc destroy_func;
86     ObMenuPlaceFunc place_func;
87
88     /* Pipe-menu parent, we get destroyed when it is destroyed */
89     ObMenu *pipe_creator;
90
91     /* The menu used as the destination for the "More..." entry for this menu*/
92     ObMenu *more_menu;
93 };
94
95 typedef enum
96 {
97     OB_MENU_ENTRY_TYPE_NORMAL,
98     OB_MENU_ENTRY_TYPE_SUBMENU,
99     OB_MENU_ENTRY_TYPE_SEPARATOR
100 } ObMenuEntryType;
101
102 struct _ObNormalMenuEntry {
103     gchar *label;
104     /*! The shortcut key that would be used to activate this menu entry */
105     gunichar shortcut;
106     /*! The shortcut's position in the string */
107     guint shortcut_position;
108
109     /* state */
110     gboolean enabled;
111
112     /* List of ObActions */
113     GSList *actions;
114
115     /* Icon shit */
116     gint icon_width;
117     gint icon_height;
118     gint icon_alpha;
119     RrPixel32 *icon_data;
120
121     /* Mask icon */
122     RrPixmapMask *mask;
123     RrColor *mask_normal_color;
124     RrColor *mask_selected_color;
125     RrColor *mask_disabled_color;
126     RrColor *mask_disabled_selected_color;
127
128     gpointer data;
129 };
130
131 struct _ObSubmenuMenuEntry {
132     gchar *name;
133     ObMenu *submenu;
134     guint show_from;
135 };
136
137 struct _ObSeparatorMenuEntry {
138     gchar *label;
139 };
140
141 struct _ObMenuEntry
142 {
143     guint ref;
144
145     ObMenuEntryType type;
146     ObMenu *menu;
147
148     gint id;
149
150     union u {
151         ObNormalMenuEntry normal;
152         ObSubmenuMenuEntry submenu;
153         ObSeparatorMenuEntry separator;
154     } data;
155 };
156
157 void menu_startup(gboolean reconfig);
158 void menu_shutdown(gboolean reconfig);
159
160 void menu_entry_ref(ObMenuEntry *self);
161 void menu_entry_unref(ObMenuEntry *self);
162
163 /*! @param allow_shortcut this should be false when the label is coming from
164            outside data like window or desktop titles */
165 ObMenu* menu_new(const gchar *name, const gchar *title,
166                  gboolean allow_shortcut_selection, gpointer data);
167 void menu_free(ObMenu *menu);
168
169 /*! Repopulate a pipe-menu by running its command */
170 void menu_pipe_execute(ObMenu *self);
171 /*! Clear a pipe-menu's entries */
172 void menu_clear_pipe_caches();
173
174 void menu_show_all_shortcuts(ObMenu *self, gboolean show);
175
176 void menu_show(gchar *name, gint x, gint y, gboolean mouse,
177                struct _ObClient *client);
178 gboolean menu_hide_delay_reached();
179
180 void menu_set_show_func(ObMenu *menu, ObMenuShowFunc func);
181 void menu_set_hide_func(ObMenu *menu, ObMenuHideFunc func);
182 void menu_set_update_func(ObMenu *menu, ObMenuUpdateFunc func);
183 void menu_set_execute_func(ObMenu *menu, ObMenuExecuteFunc func);
184 void menu_set_destroy_func(ObMenu *menu, ObMenuDestroyFunc func);
185 void menu_set_place_func(ObMenu *menu, ObMenuPlaceFunc func);
186
187 /* functions for building menus */
188 /*! @param allow_shortcut this should be false when the label is coming from
189            outside data like window or desktop titles */
190 ObMenuEntry* menu_add_normal(ObMenu *menu, gint id, const gchar *label,
191                              GSList *actions, gboolean allow_shortcut);
192 ObMenuEntry* menu_add_submenu(ObMenu *menu, gint id, const gchar *submenu);
193 ObMenuEntry* menu_add_separator(ObMenu *menu, gint id, const gchar *label);
194
195 void menu_clear_entries(ObMenu *menu);
196 void menu_entry_remove(ObMenuEntry *self);
197
198 void menu_entry_set_label(ObMenuEntry *self, const gchar *label,
199                           gboolean allow_shortcut);
200
201 ObMenuEntry* menu_find_entry_id(ObMenu *self, gint id);
202
203 /* fills in the submenus, for use when a menu is being shown */
204 void menu_find_submenus(ObMenu *self);
205
206 ObMenuEntry* menu_get_more(ObMenu *menu, guint show_from);
207
208 #endif