X11 Work Bench Toolkit  1.0
menu.h
Go to the documentation of this file.
1 
2 // _ //
3 // _ __ ___ ___ _ __ _ _ | |__ //
4 // | '_ ` _ \ / _ \| '_ \ | | | | | '_ \ //
5 // | | | | | || __/| | | || |_| | _| | | | //
6 // |_| |_| |_| \___||_| |_| \__,_|(_)_| |_| //
7 // //
8 // generic menu resource implementation //
9 // //
11 
12 /*****************************************************************************
13 
14  X11workbench - X11 programmer's 'work bench' application and toolkit
15  Copyright (c) 2010-2016 by Bob Frazier (aka 'Big Bad Bombastic Bob')
16  all rights reserved
17 
18  DISCLAIMER: The X11workbench application and toolkit software are supplied
19  'as-is', with no warranties, either implied or explicit.
20  Any claims to alleged functionality or features should be
21  considered 'preliminary', and might not function as advertised.
22 
23  BSD-like license:
24 
25  There is no restriction as to what you can do with this software, so long
26  as you include the above copyright notice and DISCLAIMER for any distributed
27  work that is equal to or derived from this one, along with this paragraph
28  that explains the terms of the license if the source is also being made
29  available. A "derived work" describes a work that uses a significant portion
30  of the source files or algorithms that are included with this one.
31  Specifically excluded from this are files that were generated by the software,
32  or anything that is included with the software that is part of another package
33  (such as files that were created or added during the 'configure' process).
34  Specifically included is the use of part or all of any of the X11 workbench
35  toolkit source or header files in your distributed application. If you do not
36  ship the source, the above copyright statement is still required to be placed
37  in a reasonably prominent place, such as documentation, splash screens, and/or
38  'about the application' dialog boxes.
39 
40  Use and distribution are in accordance with GPL, LGPL, and/or the above
41  BSD-like license. See COPYING and README files for more information.
42 
43 
44  Additional information at http://sourceforge.net/projects/X11workbench
45 
46 ******************************************************************************/
47 
62 // a menu bar is a window that contains one or more text menu items, displaying a popup menu
63 // whenever a text menu item is activated. The popup menu is displayed as needed.
64 
65 #ifndef MENU_H_INCLUDED
66 #define MENU_H_INCLUDED
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif // __cplusplus
71 
72 
76 #define WBMENU_RESERVE_DEFAULT (256 * sizeof(void *))
78 #define WBMENU_POPUP_HIGH_BIT 0x80000000
79 #define WBMENU_DYNAMIC_HIGH_BIT 0x40000000
80 #define WBMENU_POPUP_MASK 0x3fffffff
81 #define WBMENU_SEPARATOR -1
127 typedef struct __WBMenuItem__
128 {
129  unsigned int uiTag;
130 
131  // the following data members are offsets from 'data' for each component of the menu item
132  // '-1' generically indicates "none"
136  int iHotKey;
137 
138  // the following data members are numeric properties (not offsets)
139  int iAction;
140 
141  int nHotKey;
143  int iPosition;
144 
145  int nDataSize;
146  char data[4];
147 
148 } WBMenuItem;
149 
150 
185 typedef struct __WBMenu
186 {
187  unsigned int uiTag;
188 
189  int iMenuID;
190 
192  int nItems;
193  int nMaxItems;
194 
195  struct __WBMenu **ppPopups;
196  int nPopups;
198 
199 } WBMenu;
200 
201 #define WBMENU_TAG (*((const unsigned int *)"WBMM"))
202 #define WBMENUITEM_TAG (*((const unsigned int *)"WBMI"))
203 
204 
205 //------------------------------
206 // construction and destruction
207 //------------------------------
208 
222 WBMenu *MBCreateMenu(int iID, int iPopup, const char *pszResource, int iReserveSpace);
223  // pass in full menu resource 'pszResource' including any referenced popup menus. If a popup menu
224  // isn't specified here it can be added later via 'MBAddPopupMenu'. Specify '-1' for iID to
225  // read ID (and popup specifier) from the menu resource. 'iPopup' is non-zero for popup, zero for bar
226 
237 void MBDestroyMenu(WBMenu *pMenu); // always destroy with this function
238 
250 WBMenu *MBCopyMenu(const WBMenu *pMenu, int iReserveSpace);
251 
262 int MBIsMenuValid(const WBMenu *pMenu);
263 
264 //------------
265 // menu items
266 //------------
267 
282 WBMenuItem *MBCreateMenuItem(const char **ppszResource); // create single menu item, and point *ppszResource to next item in resource
283 
294 void MBDestroyMenuItem(WBMenuItem *pMenuItem);
295 
306 int MBIsMenuItemValid(const WBMenuItem *pMenuItem);
307 
321 int MBAddMenuItem(WBMenu *pMenu, const WBMenuItem *pMenuItem, int iPos);
322 
334 void MBRemoveMenuItem(WBMenu *pMenu, int iPos); // deletes menu item - 'iPos' has same semantics as above
335 
336 //-------------
337 // popup menus
338 //-------------
339 
353 int MBAddPopupMenu(WBMenu *pMenu, const WBMenu *pPopupMenu); // use this when you add a popup menu item to add the actual popup menu
354 
370 WBMenu *MBFindPopupMenu(WBMenu *pMenu, int idPopup);
371 
383 void MBRemovePopupMenu(WBMenu *pMenu, int idPopup);
384 
385 
396 static __inline__ int MBMenuIsPopup(WBMenu *pMenu)
397 {
398  return pMenu && (pMenu->iMenuID & WBMENU_POPUP_HIGH_BIT);
399 }
400 
413 int MBMenuProcessHotKey(WBMenu *pMenu, XKeyEvent *pEvent); // menu owner calls this to check for menu-based hotkeys
414 
415 #ifdef __cplusplus
416 };
417 #endif // __cplusplus
418 
419 #endif // MENU_H_INCLUDED
420