LibMB 1.12
mbmenu.h
1#ifndef _MBMENU_H_
2#define _MBMENU_H_
3
4/* libmb
5 * Copyright (C) 2002 Matthew Allum
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23#include <libmb/mbconfig.h>
24
25#include <stdio.h>
26#include <unistd.h>
27#include <stdlib.h>
28#include <string.h>
29#include <sys/types.h>
30#include <sys/stat.h>
31#include <dirent.h>
32#include <signal.h>
33#include <sys/wait.h>
34#include <X11/Xlib.h>
35#include <X11/Xutil.h>
36#include <X11/Xatom.h>
37
38#include <X11/Xresource.h>
39#include <X11/extensions/shape.h>
40#include <X11/Xatom.h>
41#include <X11/keysymdef.h>
42#include <X11/keysym.h>
43#include <X11/Xmd.h>
44
45#include <libmb/xsettings-client.h>
46#include <libmb/mbpixbuf.h>
47#include <libmb/mbexp.h>
48
58/*
59 TODO?
60
61 - mb_menu menu calls to mb_menu_menu ?
62*/
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68
74typedef enum {
75 MBMENU_SET_BG_COL,
76 MBMENU_SET_FG_COL,
77 MBMENU_SET_HL_COL,
78 MBMENU_SET_BD_COL
80
86typedef enum {
87 MBMENU_NO_SORT = (1<<1),
88 MBMENU_PREPEND = (1<<2)
90
91enum {
92 MBMENU_ITEM_APP,
93 MBMENU_ITEM_FOLDER,
94 MBMENU_ITEM_SEPERATOR
95};
96
97/* for mb_menu_new */
98#define MBMENU_FG_COL (1<<1)
99#define MBMENU_BG_COL (1<<2)
100#define MBMENU_HL_COL (1<<3)
101#define MBMENU_BD_COL (1<<4)
102#define MBMENU_FONT (1<<5)
103#define MBMENU_BD_SZ (1<<6)
104#define MBMENU_ICON_SZ (1<<7)
105#define MBMENU_ICON_FN (1<<8)
106#define MBMENU_ICON_FOLDER_FN (1<<9)
107#define MBMENU_TRANS (1<<10)
108#define MBMENU_BG_FN (1<<11)
109#define MBMENU_BEVEL (1<<12)
110
111typedef struct _menu_options
112{
113 char *fontname;
114 char *foreground_col_spec;
115 char *background_col_spec;
116 char *highlight_col_spec;
117 char *border_col_spec;
118 int border_size;
119 int icon_dimention;
120 char *default_icon_filename;
121 char *default_folder_icon_filename;
122 char *bg_img_filename;
123 int transparency_level;
124 int bevel_size;
125
126} MBMenuOptions;
127
133typedef struct _menu
134{
135
136 /*
137#ifdef USE_XFT
138 XftDraw *xftdraw;
139 XftDraw *shadow_xftdraw;
140 XftDraw *active_xftdraw;
141 int expose_cnt;
142#endif
143 */
144
145 char *title;
146 struct _menuitem *items;
147 struct _menuitem *active_item;
148 struct _menuitem *too_big_start_item;
149 struct _menuitem *too_big_end_item;
150 struct _menuitem *parent_item;
151
152 int x;
153 int y;
154 int width;
155 int height;
156 int depth;
157
158 Window win;
159
160 GC mask_gc;
161 Bool too_big;
162
163 MBDrawable *active_item_drw;
164 MBDrawable *backing;
165
166
168
169
175typedef struct _menuitem
176{
177 int type;
178
179 char *title;
180 void (* cb)( struct _menuitem *item );
181 void *cb_data;
182 char *info;
183 char *icon_fn;
184
185 MBPixbufImage *img;
186
187 MBMenuMenu *child;
188 struct _menuitem *next_item;
189
190 int y;
191 int h;
192
193
194} MBMenuItem; /* XXX MBMenuItem */
195
201typedef struct _mbmemu
202{
203 Display *dpy;
204 Window root;
205 int screen;
206 MBFont *font;
207
208 /*
209#ifdef USE_XFT
210 XftFont *xftfont;
211 XftColor fg_xftcol;
212 XftColor bg_xftcol;
213 XftColor hl_xftcol;
214 XftColor bd_xftcol;
215 XftColor shadow_xftcol;
216#else
217 XFontStruct* font;
218#endif
219 XColor fg_xcol;
220 XColor bg_xcol;
221 XColor hl_xcol;
222 XColor bd_xcol;
223 */
224
225 MBColor *fg_col;
226 MBColor *bg_col;
227 MBColor *hl_col;
228 MBColor *bd_col;
229
230
231 GC gc;
232
233 Bool have_highlight_col;
234
235 int options;
236
237 int border_width; /* X window border */
238 int inner_border_width; /* Non X border */
239 XColor border_cols[3];
240 int trans;
241
242 int icon_dimention; /* 0 - no icons, else icon size after scale */
243
244 MBPixbuf *pb;
245 MBPixbufImage *img_default_folder;
246 MBPixbufImage *img_default_app;
247 MBPixbufImage *img_bg;
248
249 Pixmap arrow_icon, arrow_mask; /* XXX Togo */
250 Pixmap bg_pixmap, bg_pixmap_mask;
251
252 struct _menu *rootmenu;
253 Bool xmenu_is_active;
254 struct _menu *active[10];
255 int active_depth;
256
257 Atom atom_mbtheme;
258
259 struct _menu *keyboard_focus_menu;
260
261 XSettingsClient *xsettings_client;
262
264
270typedef void (*MBMenuActivateCB)( MBMenuItem *item ) ;
271
279MBMenu *
280mb_menu_new(Display *dpy, int screen);
281
289Bool
291 char *font_desc);
292
301Bool
302mb_menu_set_default_icons(MBMenu *mbmenu, char *folder, char *app);
303
304
312void
313mb_menu_set_icon_size(MBMenu *mbmenu, int size);
314
322void
324 MBMenuColorElement element,
325 char *col_spec);
326
334void
335mb_menu_set_trans(MBMenu *mbmenu, int trans);
336
345
346
355Bool
356mb_menu_get_root_menu_size(MBMenu *mbmenu, int *width, int *height);
357
358
367void
369 MBMenuMenu *menu,
370 int flags);
371
384 char *path,
385 char *icon_path,
386 int flags);
387
395 MBMenuMenu *menu);
396
397
403void mb_menu_free(MBMenu *mbmenu);
404
412
422 int x,
423 int y);
424
431
432
440void mb_menu_handle_xevent(MBMenu *mbmenu, XEvent *xevent);
441
456 MBMenuMenu *menu,
457 char *title,
458 MBMenuActivateCB activate_callback ,
459 void *user_data,
461 );
462
463
464MBMenuItem * /* XXX TOGO */
465mb_menu_add_item_to_menu(MBMenu *mbmenu,
466 MBMenuMenu *menu,
467 char *title,
468 char *icon,
469 char *info,
470 void (* cmd)( MBMenuItem *item ),
471 void *cb_data,
472 int flags);
473
481void
483
490void*
492
501
509void mb_menu_dump(MBMenu *mbmenu, MBMenuMenu *menu);
510
511#ifdef __cplusplus
512}
513#endif
514
515
516
520#endif
struct MBColor MBColor
Its not recommended you touch structure internals directly.
struct MBDrawable MBDrawable
Type for representing an mbdrawable.
struct MBFont MBFont
Its not recommended you touch structure internals directly.
void mb_menu_item_icon_set(MBMenu *mbmenu, MBMenuItem *item, MBPixbufImage *img)
Adds a new menu item to a menu.
void mb_menu_set_icon_size(MBMenu *mbmenu, int size)
Sets the icon dimention in pixels used by the referenced menu instance.
void mb_menu_deactivate(MBMenu *mbmenu)
Deactivates ( hides ) a mbmenu instance.
void mb_menu_add_seperator_to_menu(MBMenu *mbmenu, MBMenuMenu *menu, int flags)
Adds a seperator to a menu.
void * mb_menu_item_get_user_data(MBMenuItem *item)
Gets any user data attatched to a menu item.
void mb_menu_free(MBMenu *mbmenu)
Free's a mbmenu toplevel instance.
Bool mb_menu_set_font(MBMenu *mbmenu, char *font_desc)
Sets the font used by the referenced menu.
struct _mbmemu MBMenu
Opaque type for a 'top level' menu.
MBMenuMenu * mb_menu_get_root_menu(MBMenu *mbmenu)
Gets the top level MBMenu menu.
void mb_menu_set_col(MBMenu *mbmenu, MBMenuColorElement element, char *col_spec)
Sets the font used by the referenced menu instance.
struct _menuitem MBMenuItem
Opaque type for a menu item.
void mb_menu_remove_menu(MBMenu *mbmenu, MBMenuMenu *menu)
Removes a menu and all of its sub menus.
void(* MBMenuActivateCB)(MBMenuItem *item)
Callback for an activated menu item.
Definition: mbmenu.h:270
void mb_menu_handle_xevent(MBMenu *mbmenu, XEvent *xevent)
Processes an X Event.
void mb_menu_set_trans(MBMenu *mbmenu, int trans)
Sets the menu's transparency level.
MBMenuMenu * mb_menu_add_path(MBMenu *mbmenu, char *path, char *icon_path, int flags)
Adds single or multiple new menus to an mbmenu instance.
void mb_menu_dump(MBMenu *mbmenu, MBMenuMenu *menu)
Dumps an mbmenu menu structure to stdout.
Bool mb_menu_get_root_menu_size(MBMenu *mbmenu, int *width, int *height)
Gets the top level MBMenu menu size.
Bool mb_menu_is_active(MBMenu *mbmenu)
Checks to see if specified menu intance is active ( ie popped up )
void mb_menu_item_remove(MBMenu *mbmenu, MBMenuMenu *menu, MBMenuItem *item)
Removes a menu item.
MBMenuItemAddFlags
Used to specify how an item is added to a menu.
Definition: mbmenu.h:86
void mb_menu_activate(MBMenu *mbmenu, int x, int y)
Checks to see if specified menu intance is active ( ie popped up )
MBMenu * mb_menu_new(Display *dpy, int screen)
Creates a new toplevel mbmenu instance.
MBMenuItem * mb_menu_new_item(MBMenu *mbmenu, MBMenuMenu *menu, char *title, MBMenuActivateCB activate_callback, void *user_data, MBMenuItemAddFlags flags)
Adds a new menu item to a menu.
struct _menu MBMenuMenu
Opaque type for a menu.
Bool mb_menu_set_default_icons(MBMenu *mbmenu, char *folder, char *app)
Sets the default icons to be uses when not supplied by an individual item.
MBMenuColorElement
Used to set various menu elements colours.
Definition: mbmenu.h:74
struct MBPixbufImage MBPixbufImage
Type for representing an mbpixbuf image.
struct MBPixbuf MBPixbuf
Opaque structure used for all operations.