]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/menu.h
merge in r6153-6154 from the 3.4 branch
[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 "action.h"
23 #include "window.h"
24 #include "geom.h"
25 #include "render/render.h"
26 #include "parser/parse.h"
27
28 #include <glib.h>
29
30 struct _ObClient;
31 struct _ObMenuFrame;
32 struct _ObMenuEntryFrame;
33
34 typedef struct _ObMenu ObMenu;
35 typedef struct _ObMenuEntry ObMenuEntry;
36 typedef struct _ObNormalMenuEntry ObNormalMenuEntry;
37 typedef struct _ObSubmenuMenuEntry ObSubmenuMenuEntry;
38 typedef struct _ObSeparatorMenuEntry ObSeparatorMenuEntry;
39
40 typedef gboolean (*ObMenuUpdateFunc)(struct _ObMenuFrame *frame,
41                                      gpointer data);
42 typedef void (*ObMenuExecuteFunc)(struct _ObMenuEntry *entry,
43                                   guint state, gpointer data, Time time);
44 typedef void (*ObMenuDestroyFunc)(struct _ObMenu *menu, gpointer data);
45 /*! @param x is the mouse x coordinate. on return it should be the x coordinate
46              for the menu
47     @param y is the mouse y coordinate. on return it should be the y coordinate
48              for the menu
49 */
50 typedef void (*ObMenuPlaceFunc)(struct _ObMenuFrame *frame, gint *x, gint *y,
51                                 gint button, gpointer data);
52
53 struct _ObMenu
54 {
55     /* Name of the menu. Used in the showmenu action. */
56     gchar *name;
57     /* Displayed title */
58     gchar *title;
59     /*! The shortcut key that would be used to activate this menu if it was
60       displayed as a submenu */
61     gunichar shortcut;
62     /*! The shortcut's position in the string */
63     guint shortcut_position;
64
65     /*! If the shortcut key should be shown in menu entries even when it
66       is the first character in the string */
67     gboolean show_all_shortcuts;
68
69     /* Command to execute to rebuild the menu */
70     gchar *execute;
71
72     /* ObMenuEntry list */
73     GList *entries;
74
75     /* plugin data */
76     gpointer data;
77
78     ObMenuUpdateFunc update_func;
79     ObMenuExecuteFunc execute_func;
80     ObMenuDestroyFunc destroy_func;
81     ObMenuPlaceFunc place_func;
82
83     /* Pipe-menu parent, we get destroyed when it is destroyed */
84     ObMenu *pipe_creator;
85
86     /* The menu used as the destination for the "More..." entry for this menu*/
87     ObMenu *more_menu;
88 };
89
90 typedef enum
91 {
92     OB_MENU_ENTRY_TYPE_NORMAL,
93     OB_MENU_ENTRY_TYPE_SUBMENU,
94     OB_MENU_ENTRY_TYPE_SEPARATOR
95 } ObMenuEntryType;
96
97 struct _ObNormalMenuEntry {
98     gchar *label;
99     /*! The shortcut key that would be used to activate this menu entry */
100     gunichar shortcut;
101     /*! The shortcut's position in the string */
102     guint shortcut_position;
103
104     /* state */
105     gboolean enabled;
106
107     /* List of ObActions */
108     GSList *actions;
109
110     /* Icon shit */
111     gint icon_width;
112     gint icon_height;
113     RrPixel32 *icon_data;
114
115     /* Mask icon */
116     RrPixmapMask *mask;
117     RrColor *mask_normal_color;
118     RrColor *mask_selected_color;
119     RrColor *mask_disabled_color;
120     RrColor *mask_disabled_selected_color;
121 };
122
123 struct _ObSubmenuMenuEntry {
124     gchar *name;
125     ObMenu *submenu;
126     guint show_from;
127 };
128
129 struct _ObSeparatorMenuEntry {
130     gchar *label;
131 };
132
133 struct _ObMenuEntry
134 {
135     guint ref;
136
137     ObMenuEntryType type;
138     ObMenu *menu;
139
140     gint id;
141
142     union u {
143         ObNormalMenuEntry normal;
144         ObSubmenuMenuEntry submenu;
145         ObSeparatorMenuEntry separator;
146     } data;
147 };
148
149 void menu_startup(gboolean reconfig);
150 void menu_shutdown(gboolean reconfig);
151
152 void menu_entry_ref(ObMenuEntry *self);
153 void menu_entry_unref(ObMenuEntry *self);
154
155 /*! @param allow_shortcut this should be false when the label is coming from
156            outside data like window or desktop titles */
157 ObMenu* menu_new(const gchar *name, const gchar *title,
158                  gboolean allow_shortcut_selection, gpointer data);
159 void menu_free(ObMenu *menu);
160
161 /* Repopulate a pipe-menu by running its command */
162 void menu_pipe_execute(ObMenu *self);
163
164 void menu_show_all_shortcuts(ObMenu *self, gboolean show);
165
166 void menu_show(gchar *name, gint x, gint y, gint button,
167                struct _ObClient *client);
168
169 void menu_set_update_func(ObMenu *menu, ObMenuUpdateFunc func);
170 void menu_set_execute_func(ObMenu *menu, ObMenuExecuteFunc func);
171 void menu_set_destroy_func(ObMenu *menu, ObMenuDestroyFunc func);
172 void menu_set_place_func(ObMenu *menu, ObMenuPlaceFunc func);
173
174 /* functions for building menus */
175 /*! @param allow_shortcut this should be false when the label is coming from
176            outside data like window or desktop titles */
177 ObMenuEntry* menu_add_normal(ObMenu *menu, gint id, const gchar *label,
178                              GSList *actions, gboolean allow_shortcut);
179 ObMenuEntry* menu_add_submenu(ObMenu *menu, gint id, const gchar *submenu);
180 ObMenuEntry* menu_add_separator(ObMenu *menu, gint id, const gchar *label);
181
182 void menu_clear_entries(ObMenu *menu);
183 void menu_entry_remove(ObMenuEntry *self);
184
185 void menu_entry_set_label(ObMenuEntry *self, const gchar *label,
186                           gboolean allow_shortcut);
187
188 ObMenuEntry* menu_find_entry_id(ObMenu *self, gint id);
189
190 /* fills in the submenus, for use when a menu is being shown */
191 void menu_find_submenus(ObMenu *self);
192
193 ObMenuEntry* menu_get_more(ObMenu *menu, guint show_from);
194
195 #endif