1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 menu.h for the Openbox window manager
4 Copyright (c) 2003-2007 Dana Jansens
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.
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.
16 See the COPYING file for a copy of the GNU General Public License.
24 #include "obrender/render.h"
31 struct _ObMenuEntryFrame;
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;
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,
43 typedef void (*ObMenuExecuteFunc)(struct _ObMenuEntry *entry,
44 struct _ObMenuFrame *frame,
45 struct _ObClient *client,
46 guint state, gpointer data);
47 typedef void (*ObMenuCleanupFunc)(struct _ObMenu *menu, gpointer data);
48 typedef void (*ObMenuDestroyFunc)(struct _ObMenu *menu, gpointer data);
49 /*! @param x is the mouse x coordinate. on return it should be the x coordinate
51 @param y is the mouse y coordinate. on return it should be the y coordinate
54 typedef void (*ObMenuPlaceFunc)(struct _ObMenuFrame *frame, gint *x, gint *y,
55 gboolean mouse, gpointer data);
59 /* Name of the menu. Used in the showmenu action. */
64 /*! The shortcut key that would be used to activate this menu if it was
65 displayed as a submenu */
67 /*! The shortcut's position in the string */
68 guint shortcut_position;
69 /*! If the shortcut was specified by & and should always be drawn */
70 gboolean shortcut_always_show;
72 /*! If the shortcut key should be shown in menu entries even when it
73 is the first character in the string */
74 gboolean show_all_shortcuts;
76 /* Command to execute to rebuild the menu */
79 /* ObMenuEntry list */
85 ObMenuShowFunc show_func;
86 ObMenuHideFunc hide_func;
87 ObMenuUpdateFunc update_func;
88 ObMenuExecuteFunc execute_func;
89 ObMenuCleanupFunc cleanup_func;
90 ObMenuDestroyFunc destroy_func;
91 ObMenuPlaceFunc place_func;
93 /* Pipe-menu parent, we get destroyed when it is destroyed */
96 /* The menu used as the destination for the "More..." entry for this menu*/
102 OB_MENU_ENTRY_TYPE_NORMAL,
103 OB_MENU_ENTRY_TYPE_SUBMENU,
104 OB_MENU_ENTRY_TYPE_SEPARATOR
107 struct _ObNormalMenuEntry {
108 /* Icon stuff. If you set this, make sure you RrImageRef() it too. */
114 /*! The shortcut key that would be used to activate this menu entry */
116 /*! The shortcut's position in the string */
117 guint shortcut_position;
118 /*! If the shortcut was specified by & and should always be drawn */
119 gboolean shortcut_always_show;
124 struct _ObActionList *actions;
128 RrColor *mask_normal_color;
129 RrColor *mask_selected_color;
130 RrColor *mask_disabled_color;
131 RrColor *mask_disabled_selected_color;
136 struct _ObSubmenuMenuEntry {
137 /* Icon stuff. If you set this, make sure you RrImageRef() it too. */
147 struct _ObSeparatorMenuEntry {
155 ObMenuEntryType type;
161 ObNormalMenuEntry normal;
162 ObSubmenuMenuEntry submenu;
163 ObSeparatorMenuEntry separator;
167 void menu_startup(gboolean reconfig);
168 void menu_shutdown(gboolean reconfig);
170 void menu_entry_ref(ObMenuEntry *self);
171 void menu_entry_unref(ObMenuEntry *self);
173 ObMenu* menu_new(const gchar *name, const gchar *title,
174 gboolean allow_shortcut_selection, gpointer data);
175 void menu_free(ObMenu *menu);
177 /*! Repopulate a pipe-menu by running its command */
178 void menu_pipe_execute(ObMenu *self);
179 /*! Clear a pipe-menu's entries */
180 void menu_clear_pipe_caches(void);
182 void menu_show_all_shortcuts(ObMenu *self, gboolean show);
184 void menu_show(gchar *name, gint x, gint y, gboolean mouse,
185 struct _ObClient *client);
186 gboolean menu_hide_delay_reached(void);
188 /*! The show function is called right after a menu is shown */
189 void menu_set_show_func(ObMenu *menu, ObMenuShowFunc func);
190 /*! The hide function is called right before a menu is hidden */
191 void menu_set_hide_func(ObMenu *menu, ObMenuHideFunc func);
192 /*! The update function is called when the menu should refresh its
193 contents, generally right before it is shown */
194 void menu_set_update_func(ObMenu *menu, ObMenuUpdateFunc func);
195 /*! The execute function is called when a user chooses to execute an
197 void menu_set_execute_func(ObMenu *menu, ObMenuExecuteFunc func);
198 /*! The cleanup function is called after a menu is hidden, allowing it
199 to be cleaned up between uses */
200 void menu_set_cleanup_func(ObMenu *menu, ObMenuCleanupFunc func);
201 /*! The destroy function is called when the menu is being destroyed
203 void menu_set_destroy_func(ObMenu *menu, ObMenuDestroyFunc func);
204 /*! The place function is called when the menu is being shown and allows
205 the menu to choose its initial position */
206 void menu_set_place_func(ObMenu *menu, ObMenuPlaceFunc func);
208 /* functions for building menus */
209 /*! @param allow_shortcut this should be false when the label is coming from
210 outside data like window or desktop titles */
211 ObMenuEntry* menu_add_normal(ObMenu *menu, gint id, const gchar *label,
212 struct _ObActionList *actions,
213 gboolean allow_shortcut);
214 ObMenuEntry* menu_add_submenu(ObMenu *menu, gint id, const gchar *submenu);
215 ObMenuEntry* menu_add_separator(ObMenu *menu, gint id, const gchar *label);
217 /*! This sorts groups of menu entries between consecutive separators */
218 void menu_sort_entries(ObMenu *self);
220 void menu_clear_entries(ObMenu *self);
221 void menu_entry_remove(ObMenuEntry *self);
223 void menu_entry_set_label(ObMenuEntry *self, const gchar *label,
224 gboolean allow_shortcut);
226 ObMenuEntry* menu_find_entry_id(ObMenu *self, gint id);
228 /* fills in the submenus, for use when a menu is being shown */
229 void menu_find_submenus(ObMenu *self);
231 ObMenuEntry* menu_get_more(ObMenu *menu, guint show_from);