X11 Work Bench Toolkit  1.0
menu_bar.h
Go to the documentation of this file.
1 
2 // _ _ //
3 // _ __ ___ ___ _ __ _ _ | |__ __ _ _ __ | |_ //
4 // | '_ ` _ \ / _ \| '_ \ | | | | | '_ \ / _` || '__|| '_ \ //
5 // | | | | | || __/| | | || |_| | | |_) || (_| || | _ | | | | //
6 // |_| |_| |_| \___||_| |_| \__,_|_____|_.__/ \__,_||_|(_)|_| |_| //
7 // |_____| //
8 // //
9 // generic menu bar implementation //
10 // //
12 
13 /*****************************************************************************
14 
15  X11workbench - X11 programmer's 'work bench' application and toolkit
16  Copyright (c) 2010-2016 by Bob Frazier (aka 'Big Bad Bombastic Bob')
17  all rights reserved
18 
19  DISCLAIMER: The X11workbench application and toolkit software are supplied
20  'as-is', with no warranties, either implied or explicit.
21  Any claims to alleged functionality or features should be
22  considered 'preliminary', and might not function as advertised.
23 
24  BSD-like license:
25 
26  There is no restriction as to what you can do with this software, so long
27  as you include the above copyright notice and DISCLAIMER for any distributed
28  work that is equal to or derived from this one, along with this paragraph
29  that explains the terms of the license if the source is also being made
30  available. A "derived work" describes a work that uses a significant portion
31  of the source files or algorithms that are included with this one.
32  Specifically excluded from this are files that were generated by the software,
33  or anything that is included with the software that is part of another package
34  (such as files that were created or added during the 'configure' process).
35  Specifically included is the use of part or all of any of the X11 workbench
36  toolkit source or header files in your distributed application. If you do not
37  ship the source, the above copyright statement is still required to be placed
38  in a reasonably prominent place, such as documentation, splash screens, and/or
39  'about the application' dialog boxes.
40 
41  Use and distribution are in accordance with GPL, LGPL, and/or the above
42  BSD-like license. See COPYING and README files for more information.
43 
44 
45  Additional information at http://sourceforge.net/projects/X11workbench
46 
47 ******************************************************************************/
48 
66 #ifndef MENU_BAR_H_INCLUDED
67 #define MENU_BAR_H_INCLUDED
68 
69 #include "menu.h"
70 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif // __cplusplus
74 
75 
76 #define MENU_WINDOW_TAG (*((const unsigned int *)"MWMW"))
77 
113 typedef struct __WBMenuBarWindow__
114 {
115  unsigned int ulTag;
116  Window wSelf;
117  Window wOwner;
118 
120 
121  int iX;
122  int iY;
123  int iWidth;
124  int iHeight;
125  int iSelected;
126  int iPrevSel;
127  int iFlags;
128 
130 
131 
132 // Initialization, global objects, and default objects
133 
143 int MBInitGlobal(void);
144 
149 extern XColor clrMenuFG;
150 extern XColor clrMenuBG;
151 extern XColor clrMenuActiveFG;
152 extern XColor clrMenuActiveBG;
153 extern XColor clrMenuBorder1;
154 extern XColor clrMenuBorder2;
155 extern XColor clrMenuBorder3;
156 extern XColor clrMenuDisabledFG;
157 extern XColor clrMenuActiveDisabledFG;
158 
162 // these are documented in menu_bar.c
163 extern Atom aMENU_RESIZE;
164 extern Atom aMENU_DISPLAY_POPUP;
165 extern Atom aMENU_ACTIVATE;
166 
167 
177 XFontStruct *MBGetDefaultMenuFont(void);
178 
179 // menu bar window info
180 
191 static __inline__ WBMenuBarWindow *MBGetMenuBarWindowStruct(Window wID) // for frame windows, returns the frame window struct
192 {
193  WBMenuBarWindow *pRval = (WBMenuBarWindow *)WBGetWindowData(wID, 0); // offset 0 for window-specific structs
194 
195  if(pRval && pRval->ulTag == MENU_WINDOW_TAG)
196  {
197  return(pRval);
198  }
199 
200  return(NULL);
201 }
202 
216 WBMenuBarWindow *MBCreateMenuBarWindow(Window wIDParent, const char *pszResource, int iFlags);
217 
228 WBMenuBarWindow *MBFindMenuBarWindow(WBMenu *pMenu); // find first (active) window that uses 'pMenu'
229 
230 
242 void MBReCalcMenuBarWindow(WBMenuBarWindow *pMenuBar);
243 
244 
256 void MBDestroyMenuBarWindow(WBMenuBarWindow *pMenuBar); // destroy by using struct pointer
257 
258 
269 static __inline__ WBMenu * MBGetMenuBarMenu(WBMenuBarWindow *pMenuBar)
270 {
271  if(!pMenuBar || pMenuBar->ulTag != MENU_WINDOW_TAG)
272  {
273  return NULL;
274  }
275 
276  return pMenuBar->pMenu;
277 }
278 
292 static __inline__ WBMenu * MBSetMenuBarMenu(WBMenuBarWindow *pMenuBar, WBMenu *pMenu)
293 {
294 WBMenu *pRval;
295 
296  if(!pMenuBar || pMenuBar->ulTag != MENU_WINDOW_TAG)
297  {
298  return NULL;
299  }
300 
301  pRval = pMenuBar->pMenu;
302  pMenuBar->pMenu = pMenu; // TODO: reference counting?
303  pMenuBar->iSelected = -1;
304  pMenuBar->iPrevSel = -1;
305 
306  MBReCalcMenuBarWindow(pMenuBar);
307 
308  return pRval; // the old menu
309 }
310 
323 void MBSetMenuBarMenuResource(WBMenuBarWindow *pMenuBar, const char *pszMenuResource);
324 
325 
326 #ifdef __cplusplus
327 };
328 #endif // __cplusplus
329 
330 
331 #endif // MENU_BAR_H_INCLUDED
332