X11workbench Toolkit  1.0
menu_bar.h
Go to the documentation of this file.
1 // _ _ //
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-2019 by Bob Frazier (aka 'Big Bad Bombastic Bob')
17 
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  MIT-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  MIT-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 tagWBMenuBarWindow
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 
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 
XColor clrMenuActiveFG
menu 'active' foreground color
Definition: menu_bar.c:113
int MBInitGlobal(void)
Initialize global resources for Menu Bar windows.
Definition: menu_bar.c:177
Atom aMENU_DISPLAY_POPUP
Atom for 'DISPLAY POPUP' client event.
Definition: menu_bar.c:165
int iX
menu bar 'X' position within the owner's client area
Definition: menu_bar.h:121
void * WBGetWindowData(Window wID, int iIndex)
Gets the data associated with this window and the specified index.
structure for defining a menu bar window
Definition: menu_bar.h:113
XColor clrMenuBorder1
menu border color 1
Definition: menu_bar.c:113
void MBDestroyMenuBarWindow(WBMenuBarWindow *pMenuBar)
Destroy a 'Menu Bar' window.
Definition: menu_bar.c:511
WB_FONTC MBGetDefaultMenuFont(void)
Get a pointer to the default 'Menu Bar' font structure.
Definition: menu_bar.c:338
int iPrevSel
previously selected menu item (for internal-only menu UI purposes)
Definition: menu_bar.h:126
structure for managing menu items
Definition: menu.h:185
XColor clrMenuActiveDisabledFG
menu 'disabled but active' foreground color
Definition: menu_bar.c:113
void MBSetMenuBarMenuResource(WBMenuBarWindow *pMenuBar, const char *pszMenuResource)
Assign a new WBMenu for a Menu Bar window.
Definition: menu_bar.c:530
int iWidth
menu bar width
Definition: menu_bar.h:123
void MBReCalcMenuBarWindow(WBMenuBarWindow *pMenuBar)
Cause a 'layout recalculation' for a Menu Bar window.
Definition: menu_bar.c:504
XColor clrMenuBG
menu background color
Definition: menu_bar.c:113
struct tagWBMenuBarWindow WBMenuBarWindow
structure for defining a menu bar window
XColor clrMenuBorder2
menu border color 2
Definition: menu_bar.c:113
Atom aMENU_RESIZE
Atom for 'RESIZE' client event.
Definition: menu_bar.c:130
WBMenuBarWindow * MBCreateMenuBarWindow(Window wIDParent, const char *pszResource, int iFlags)
Create a Menu Bar windows and its associated WBMenuBarWindow structure.
Definition: menu_bar.c:343
static __inline__ WBMenuBarWindow * MBGetMenuBarWindowStruct(Window wID)
Obtain a pointer to the WBMenuBarWindow structure from a Window ID of a Menu Bar window.
Definition: menu_bar.h:191
XColor clrMenuDisabledFG
menu 'disabled' foreground color
Definition: menu_bar.c:113
WBMenuBarWindow * MBFindMenuBarWindow(WBMenu *pMenu)
Locate the first WBMenuBarWindow that is using a WBMenu structure.
Definition: menu_bar.c:492
int iFlags
flags that determine behavior (reserved)
Definition: menu_bar.h:127
static __inline__ WBMenu * MBGetMenuBarMenu(WBMenuBarWindow *pMenuBar)
Get the current WBMenu for a Menu Bar window.
Definition: menu_bar.h:269
XColor clrMenuActiveBG
menu 'active' background color
Definition: menu_bar.c:113
static __inline__ WBMenu * MBSetMenuBarMenu(WBMenuBarWindow *pMenuBar, WBMenu *pMenu)
Assign a new WBMenu for a Menu Bar window.
Definition: menu_bar.h:292
Atom aMENU_ACTIVATE
Atom for 'ACTIVATE' client event.
Definition: menu_bar.c:150
Window wSelf
The window ID of the menu bar window.
Definition: menu_bar.h:116
XColor clrMenuFG
menu foreground color
Definition: menu_bar.c:113
int iSelected
currently selected menu (for internal-only menu UI purposes)
Definition: menu_bar.h:125
int iY
menu bar 'Y' position within the owner's client area
Definition: menu_bar.h:122
Window wOwner
The window ID of the owning window.
Definition: menu_bar.h:117
int iHeight
menu bar height
Definition: menu_bar.h:124
WBMenu * pMenu
a pointer to the associated WBMenu structure
Definition: menu_bar.h:119
An allocated structure containing XFontStruct, XFontInfo, and XftFont [as applicable] for a specified...
Definition: font_helper.h:152
unsigned int ulTag
tag indicating I'm a 'Menu Bar' window
Definition: menu_bar.h:115
XColor clrMenuBorder3
menu border color 3
Definition: menu_bar.c:113