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