LibMB  1.9
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 #ifdef USE_XSETTINGS
46 #include <xsettings-client.h>
47 #endif
48 
49 #include "mbpixbuf.h"
50 #include "mbexp.h"
51 
61 /*
62  TODO?
63 
64  - mb_menu menu calls to mb_menu_menu ?
65 */
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 
77 typedef enum {
78  MBMENU_SET_BG_COL,
79  MBMENU_SET_FG_COL,
80  MBMENU_SET_HL_COL,
81  MBMENU_SET_BD_COL
83 
89 typedef enum {
90  MBMENU_NO_SORT = (1<<1),
91  MBMENU_PREPEND = (1<<2)
93 
94 enum {
95  MBMENU_ITEM_APP,
96  MBMENU_ITEM_FOLDER,
97  MBMENU_ITEM_SEPERATOR
98 };
99 
100 /* for mb_menu_new */
101 #define MBMENU_FG_COL (1<<1)
102 #define MBMENU_BG_COL (1<<2)
103 #define MBMENU_HL_COL (1<<3)
104 #define MBMENU_BD_COL (1<<4)
105 #define MBMENU_FONT (1<<5)
106 #define MBMENU_BD_SZ (1<<6)
107 #define MBMENU_ICON_SZ (1<<7)
108 #define MBMENU_ICON_FN (1<<8)
109 #define MBMENU_ICON_FOLDER_FN (1<<9)
110 #define MBMENU_TRANS (1<<10)
111 #define MBMENU_BG_FN (1<<11)
112 #define MBMENU_BEVEL (1<<12)
113 
114 typedef struct _menu_options
115 {
116  char *fontname;
117  char *foreground_col_spec;
118  char *background_col_spec;
119  char *highlight_col_spec;
120  char *border_col_spec;
121  int border_size;
122  int icon_dimention;
123  char *default_icon_filename;
124  char *default_folder_icon_filename;
125  char *bg_img_filename;
126  int transparency_level;
127  int bevel_size;
128 
129 } MBMenuOptions;
130 
136 typedef struct _menu
137 {
138 
139  /*
140 #ifdef USE_XFT
141  XftDraw *xftdraw;
142  XftDraw *shadow_xftdraw;
143  XftDraw *active_xftdraw;
144  int expose_cnt;
145 #endif
146  */
147 
148  char *title;
149  struct _menuitem *items;
150  struct _menuitem *active_item;
151  struct _menuitem *too_big_start_item;
152  struct _menuitem *too_big_end_item;
153  struct _menuitem *parent_item;
154 
155  int x;
156  int y;
157  int width;
158  int height;
159  int depth;
160 
161  Window win;
162 
163  GC mask_gc;
164  Bool too_big;
165 
166  MBDrawable *active_item_drw;
167  MBDrawable *backing;
168 
169 
170 } MBMenuMenu;
171 
172 
178 typedef struct _menuitem
179 {
180  int type;
181 
182  char *title;
183  void (* cb)( struct _menuitem *item );
184  void *cb_data;
185  char *info;
186  char *icon_fn;
187 
188  MBPixbufImage *img;
189 
190  MBMenuMenu *child;
191  struct _menuitem *next_item;
192 
193  int y;
194  int h;
195 
196 
197 } MBMenuItem; /* XXX MBMenuItem */
198 
204 typedef struct _mbmemu
205 {
206  Display *dpy;
207  Window root;
208  int screen;
209  MBFont *font;
210 
211  /*
212 #ifdef USE_XFT
213  XftFont *xftfont;
214  XftColor fg_xftcol;
215  XftColor bg_xftcol;
216  XftColor hl_xftcol;
217  XftColor bd_xftcol;
218  XftColor shadow_xftcol;
219 #else
220  XFontStruct* font;
221 #endif
222  XColor fg_xcol;
223  XColor bg_xcol;
224  XColor hl_xcol;
225  XColor bd_xcol;
226  */
227 
228  MBColor *fg_col;
229  MBColor *bg_col;
230  MBColor *hl_col;
231  MBColor *bd_col;
232 
233 
234  GC gc;
235 
236  Bool have_highlight_col;
237 
238  int options;
239 
240  int border_width; /* X window border */
241  int inner_border_width; /* Non X border */
242  XColor border_cols[3];
243  int trans;
244 
245  int icon_dimention; /* 0 - no icons, else icon size after scale */
246 
247  MBPixbuf *pb;
248  MBPixbufImage *img_default_folder;
249  MBPixbufImage *img_default_app;
250  MBPixbufImage *img_bg;
251 
252  Pixmap arrow_icon, arrow_mask; /* XXX Togo */
253  Pixmap bg_pixmap, bg_pixmap_mask;
254 
255  struct _menu *rootmenu;
256  Bool xmenu_is_active;
257  struct _menu *active[10];
258  int active_depth;
259 
260  Atom atom_mbtheme;
261 
262  struct _menu *keyboard_focus_menu;
263 
264 #ifdef USE_XSETTINGS
265  XSettingsClient *xsettings_client;
266 #endif
267 
268 } MBMenu;
269 
275 typedef void (*MBMenuActivateCB)( MBMenuItem *item ) ;
276 
284 MBMenu *
285 mb_menu_new(Display *dpy, int screen);
286 
294 Bool
295 mb_menu_set_font (MBMenu *mbmenu,
296  char *font_desc);
297 
306 Bool
307 mb_menu_set_default_icons(MBMenu *mbmenu, char *folder, char *app);
308 
309 
317 void
318 mb_menu_set_icon_size(MBMenu *mbmenu, int size);
319 
327 void
328 mb_menu_set_col(MBMenu *mbmenu,
329  MBMenuColorElement element,
330  char *col_spec);
331 
339 void
340 mb_menu_set_trans(MBMenu *mbmenu, int trans);
341 
350 
351 
360 Bool
361 mb_menu_get_root_menu_size(MBMenu *mbmenu, int *width, int *height);
362 
363 
372 void
374  MBMenuMenu *menu,
375  int flags);
376 
387 MBMenuMenu
388 *mb_menu_add_path(MBMenu *mbmenu,
389  char *path,
390  char *icon_path,
391  int flags);
392 
399 void mb_menu_remove_menu(MBMenu *mbmenu,
400  MBMenuMenu *menu);
401 
402 
408 void mb_menu_free(MBMenu *mbmenu);
409 
416 Bool mb_menu_is_active(MBMenu *mbmenu);
417 
426 void mb_menu_activate(MBMenu *mbmenu,
427  int x,
428  int y);
429 
435 void mb_menu_deactivate(MBMenu *mbmenu);
436 
437 
445 void mb_menu_handle_xevent(MBMenu *mbmenu, XEvent *xevent);
446 
459 MBMenuItem *
460 mb_menu_new_item (MBMenu *mbmenu,
461  MBMenuMenu *menu,
462  char *title,
463  MBMenuActivateCB activate_callback ,
464  void *user_data,
465  MBMenuItemAddFlags flags
466  );
467 
468 
469 MBMenuItem * /* XXX TOGO */
470 mb_menu_add_item_to_menu(MBMenu *mbmenu,
471  MBMenuMenu *menu,
472  char *title,
473  char *icon,
474  char *info,
475  void (* cmd)( MBMenuItem *item ),
476  void *cb_data,
477  int flags);
478 
486 void
488 
495 void*
497 
505 void mb_menu_item_remove(MBMenu *mbmenu, MBMenuMenu *menu, MBMenuItem *item);
506 
514 void mb_menu_dump(MBMenu *mbmenu, MBMenuMenu *menu);
515 
516 #ifdef __cplusplus
517 }
518 #endif
519 
520 
521 
525 #endif