66 #include <X11/cursorfont.h> 69 #include "pixmap_helper.h" 72 #include "menu_popup.h" 99 int MBMenuParentEvent(Window wIDMenu, XEvent *pEvent);
100 int MBMenuWinEvent(Window wID, XEvent *pEvent);
103 static int MenuBarDoExposeEvent(XExposeEvent *pEvent,
WBMenu *pMenu, Display *pDisplay,
108 #define MENU_FONT "fixed" 109 #define MENU_ALT_FONT "*-fixed-*" 110 #define MENU_FONT_SIZE 13 116 static int iInitColorFlag = 0;
117 static WB_FONT pDefaultMenuFont = NULL;
170 #define DEBUG_VALIDATE(X) X 172 #define DEBUG_VALIDATE(X) if(!(X)) { WB_WARN_PRINT("%s:%d - %s\n", __FUNCTION__, __LINE__, "WARNING - " #X " failed!\n"); } 181 if(!pDefaultMenuFont)
185 if(!pDefaultMenuFont)
190 if(!pDefaultMenuFont)
194 if(!pDefaultMenuFont)
198 if(!pDefaultMenuFont)
202 if(!pDefaultMenuFont)
206 if(!pDefaultMenuFont)
217 if(!pDefaultMenuFont)
221 if(!pDefaultMenuFont)
225 WB_ERROR_PRINT(
"%s - no font, MENU FONT is %s,%s %d (menus will not be displayed)\n", __FUNCTION__, MENU_FONT, MENU_ALT_FONT, 13);
234 char szMenuFG[16], szMenuBG[16], szMenuActiveFG[16], szMenuActiveBG[16],
235 szMenuBorder1[16], szMenuActiveDisabledFG[16], szMenuDisabledFG[16];
237 int iY, iU, iV, iR, iG, iB;
239 #define COPY_COLOR_NAME(X,Y,Z) {const char *pX = X(WBGetDefaultDisplay()); if(pX) strncpy(Y,pX,sizeof(Y)); else strncpy(Y,Z,sizeof(Y));} 250 LOAD_COLOR(
"*Menu.foreground",szMenuFG,
"#000000");
251 LOAD_COLOR(
"*Menu.background",szMenuBG,
"#DCDAD5");
252 LOAD_COLOR(
"*Menu.activeForeground",szMenuActiveFG,
"#FFFFFF");
253 LOAD_COLOR(
"*Menu.activeBackground",szMenuActiveBG,
"#4B6983");
254 LOAD_COLOR(
"*Menu.disabledForeground",szMenuDisabledFG,
"#808080");
255 LOAD_COLOR(
"*Menu.disabledForeground",szMenuActiveDisabledFG,
"#808080");
256 LOAD_COLOR(
"*borderColor",szMenuBorder1,
"#000000");
284 if((
clrMenuBG.flags & (DoRed | DoGreen | DoBlue)) != (DoRed | DoGreen | DoBlue))
296 PXM_YUVToRGB((2 * iY + 256) / 3, iU, iV, &iR, &iG, &iB);
340 return pDefaultMenuFont;
349 unsigned long fg, bg, bd;
350 XSetWindowAttributes xswa;
375 if(!pDefaultMenuFont && !pFS)
380 else if(pDefaultMenuFont)
382 pFS = pDefaultMenuFont;
386 xsh.flags = (PPosition | PSize);
398 memset(&xswa, 0,
sizeof(xswa));
400 xswa.border_pixel = bd;
401 xswa.background_pixel = bg;
402 xswa.colormap = DefaultColormap(pDisplay, DefaultScreen(pDisplay));
403 xswa.bit_gravity = CenterGravity;
410 pRval->
ulTag = MENU_WINDOW_TAG;
416 WB_WARN_PRINT(
"%s - WARNING: pMenu is NULL in WBMenuBarWindow object\n", __FUNCTION__);
420 xsh.x, xsh.y, xsh.width, xsh.height, 0,
422 CWBorderPixel | CWBackPixel | CWColormap | CWBitGravity,
425 if(pRval->
wSelf == -1)
431 pRval->
wOwner = wIDParent;
436 pRval->
iX = xsh.x + 4;
437 pRval->
iY = xsh.y + 4;
438 pRval->
iWidth = xsh.width - 8;
439 pRval->
iHeight = xsh.height - 8;
442 bzero(&xwmh,
sizeof(xwmh));
443 xwmh.flags = InputHint;
457 XSelectInput(pDisplay, pRval->
wSelf,
480 static int __FindMenuBarWindowCallback(Window wID,
void *pData)
484 if(pMB && (
void *)(pMB->
pMenu) == pData)
494 Window wID =
WBLocateWindow(__FindMenuBarWindowCallback, (
void *)pMenu);
513 if(!pMenuBar || pMenuBar->
ulTag != MENU_WINDOW_TAG)
523 pMenuBar->
pMenu = NULL;
534 if(!pMenuBar || pMenuBar->
ulTag != MENU_WINDOW_TAG)
543 WB_ERROR_PRINT(
"ERROR: %s - unable to create menu\n", __FUNCTION__);
552 pMenuBar->
pMenu = pMenu;
562 int MBMenuParentEvent(Window wIDMenu, XEvent *pEvent)
573 if(pEvent->type == ConfigureNotify &&
574 pSelf->
wOwner == pEvent->xconfigure.window)
577 chg.width = pEvent->xconfigure.width;
578 XConfigureWindow(pDisplay, wIDMenu, CWWidth, &chg);
594 Window wID = pSelf->
wSelf;
598 XClientMessageEvent evt;
602 bzero(&evt,
sizeof(evt));
603 evt.type = ClientMessage;
604 evt.display = pDisplay;
615 "%s - posting client event message to display popup menu\n", __FUNCTION__);
619 XClientMessageEvent evt;
621 bzero(&evt,
sizeof(evt));
622 evt.type = ClientMessage;
624 evt.display = pDisplay;
625 evt.window = pSelf->
wOwner;
628 evt.data.l[0] = pItem->
iAction;
636 WB_DEBUG_PRINT(DebugLevel_WARN | DebugSubSystem_Menu | DebugSubSystem_Event,
637 "%s - Post Event: %08xH %08xH %pH %08xH\n", __FUNCTION__,
648 XClientMessageEvent evt;
651 bzero(&evt,
sizeof(evt));
652 evt.type = ClientMessage;
654 evt.display = pDisplay;
655 evt.window = pSelf->
wOwner;
662 evt.data.l[0] = pItem->
iAction;
680 int MBMenuWinEvent(Window wID, XEvent *pEvent)
692 if(pSelf && pEvent->type == Expose)
694 return MenuBarDoExposeEvent((XExposeEvent *)pEvent, pMenu, pDisplay, wID, pSelf);
697 if(pSelf && pEvent->type == ClientMessage && pEvent->xclient.message_type ==
aMENU_RESIZE)
700 XWindowAttributes xswa;
702 WB_DEBUG_PRINT(DebugLevel_Heavy | DebugSubSystem_Menu | DebugSubSystem_Window | DebugSubSystem_Event,
703 "%s - Resize Request Message for %d (%08xH)\n", __FUNCTION__, (
int)wID, (
int)wID);
707 XGetWindowAttributes(pDisplay, wID, &xswa);
708 xswa.width = rct.
right - rct.
left - xswa.border_width;
711 WB_DEBUG_PRINT(DebugLevel_Excessive | DebugSubSystem_Menu | DebugSubSystem_Window | DebugSubSystem_Event,
712 "%s - perform resize request for %d (%08xH) %d, %d\n",
713 __FUNCTION__, (
int)wID, (
int)wID, xswa.width, xswa.height);
715 XResizeWindow(pDisplay, wID, xswa.width, xswa.height);
720 if(pSelf && pEvent->type == DestroyNotify)
722 if(pEvent->xdestroywindow.window == wID)
733 (pEvent->type == KeyPress ||
734 pEvent->type == KeyRelease))
736 WB_DEBUG_PRINT(DebugLevel_Excessive | DebugSubSystem_Menu | DebugSubSystem_Window | DebugSubSystem_Event,
737 "%s - keypress/release in menu_bar\n", __FUNCTION__);
739 if(pEvent->type == KeyPress)
747 memcpy(&xevt, pEvent,
sizeof(*pEvent));
748 xevt.xkey.window = wIDParent;
754 bzero(&xevt,
sizeof(xevt));
755 xevt.type = ClientMessage;
757 xevt.xclient.display = pDisplay;
758 xevt.xclient.window = wIDParent;
760 xevt.xclient.format = 32;
761 xevt.xclient.data.l[0] = 0;
767 (pEvent->type == ButtonPress ||
768 pEvent->type == ButtonRelease ||
769 pEvent->type == MotionNotify))
775 if(pEvent->type == MotionNotify)
777 WBXlatCoordPoint(pEvent->xmotion.window, pEvent->xmotion.x, pEvent->xmotion.y,
779 if(pEvent->xmotion.state & Button1Mask)
784 else if(pEvent->type == ButtonPress && pMenu)
786 WBXlatCoordPoint(pEvent->xbutton.window, pEvent->xbutton.x, pEvent->xbutton.y,
788 if(pEvent->xbutton.state & (Button2Mask | Button3Mask | Button4Mask | Button5Mask
789 | ShiftMask | LockMask | ControlMask))
793 else if(iY >= pSelf->
iY && iY <= (pSelf->
iY + pSelf->
iHeight))
819 WB_DEBUG_PRINT(DebugLevel_WARN | DebugSubSystem_Menu | DebugSubSystem_Mouse,
820 "%s - couldn't find the menu item - mouse at %d, %d\n", __FUNCTION__, iX, iY);
822 let_parent_process_it:
827 bzero(&xevt,
sizeof(xevt));
828 xevt.type = ClientMessage;
830 xevt.xclient.display = pDisplay;
831 xevt.xclient.window = wIDParent;
833 xevt.xclient.format = 32;
834 xevt.xclient.data.l[0] = 0;
840 WB_DEBUG_PRINT(DebugLevel_WARN | DebugSubSystem_Menu | DebugSubSystem_Mouse,
841 "%s - Mouse pointer is out of range - %d, %d, %d, %d, %d, %d\n",
844 goto let_parent_process_it;
851 if(i1 < 0 || i1 >= pMenu->
nItems)
882 MBMenuHandleMenuItem(pDisplay, pSelf, pMenu, pItem);
890 if(pEvent && pEvent->type == ClientMessage)
892 if(((XClientMessageEvent *)pEvent)->message_type ==
aMENU_ACTIVATE)
894 int iMenuItemIndex = ((XClientMessageEvent *)pEvent)->data.l[1];
902 if(iMenuItemIndex >= 0 && iMenuItemIndex < pMenu->
nItems &&
903 ((XClientMessageEvent *)pEvent)->data.l[0])
935 MBMenuHandleMenuItem(pDisplay, pSelf, pMenu, pItem);
939 WB_DEBUG_PRINT(DebugLevel_Chatty | DebugSubSystem_Menu | DebugSubSystem_Keyboard,
940 "%s - MENU_ACTIVATE event, activate menu item, %d %p\n",
941 __FUNCTION__, iMenuItemIndex, pItem);
953 else if( !((XClientMessageEvent *)pEvent)->data.l[0])
959 if(iOldSel < 0 || iOldSel >= pMenu->
nItems)
963 if(iOldSel >=0 && iOldSel < pMenu->
nItems)
969 if(iMenuItemIndex == 0)
975 goto try_select_next;
980 else if(iMenuItemIndex > 0)
1046 MBMenuHandleMenuItem(pDisplay, pSelf, pMenu, pItem);
1049 WB_DEBUG_PRINT(DebugLevel_Chatty | DebugSubSystem_Menu | DebugSubSystem_Keyboard,
1050 "%s - MENU_ACTIVATE event, select prev/next, %d %d\n",
1051 __FUNCTION__, iMenuItemIndex, pSelf->
iSelected);
1056 WB_WARN_PRINT(
"%s - MENU_ACTIVATE event, invalid menu information, %d %d %p %p\n",
1057 __FUNCTION__, iMenuItemIndex, pMenu->
nItems,
1058 (
void *)pItem, (
void *)(((XClientMessageEvent *)pEvent)->data.l[0]));
1063 int iMenuItem = ((XClientMessageEvent *)pEvent)->data.l[0];
1064 int iPosition = ((XClientMessageEvent *)pEvent)->data.l[1];
1065 int iRightPos = ((XClientMessageEvent *)pEvent)->data.l[2];
1067 for(i1=0; i1 < pMenu->
nPopups; i1++)
1070 "%s - popup menu id = %d\n", __FUNCTION__,
1079 XWarpPointer(pDisplay, None, pSelf->
wSelf, 0, 0, 0, 0,
1080 (iPosition + iRightPos) / 2, pSelf->
iY + pSelf->
iHeight / 2);
1084 iPosition, pSelf->
iY + pSelf->
iHeight, 0);
1093 "%s - Displaying popup menu id %d\n", __FUNCTION__, iMenuItem);
1102 "%s - Done with popup menu id %d, return %d\n", __FUNCTION__, iMenuItem, i2);
1107 WB_WARN_PRINT(
"%s - Unable to create popup menu %d\n", __FUNCTION__, iMenuItem);
1119 WB_WARN_PRINT(
"%s - Unable to locate popup menu %d\n", __FUNCTION__, iMenuItem);
1129 static int MenuBarDoExposeEvent(XExposeEvent *pEvent,
WBMenu *pMenu, Display *pDisplay,
1132 int i1, i2, iHPos, iVPos;
1133 XWindowAttributes xwa;
1152 if (XGetWindowAttributes(pDisplay, wID, &xwa) == 0)
1154 WB_ERROR_PRINT(
"%s - * BUG * unable to get window attributes\n", __FUNCTION__);
1163 if(!pDefaultMenuFont)
1168 else if(pDefaultMenuFont)
1170 pFont = pDefaultMenuFont;
1178 WB_ERROR_PRINT(
"%s - * BUG * no graphics context!\n", __FUNCTION__);
1197 xpt[0].x=xwa.border_width;
1198 xpt[0].y=xwa.height-1-2*xwa.border_width - 1;
1199 xpt[1].x=xwa.border_width;
1200 xpt[1].y=xwa.border_width;
1201 xpt[2].x=xwa.width-1-2*xwa.border_width - 1;
1202 xpt[2].y=xwa.border_width;
1204 WBDrawLines(pDisplay, wID, gc, xpt, 3, CoordModeOrigin);
1207 xpt[0].x=xwa.width-1-2*xwa.border_width;
1208 xpt[0].y=xwa.border_width + 1;
1209 xpt[1].x=xwa.width-1-2*xwa.border_width;
1210 xpt[1].y=xwa.height-1-2*xwa.border_width;
1211 xpt[2].x=xwa.border_width + 1;
1212 xpt[2].y=xwa.height-1-2*xwa.border_width;
1214 WBDrawLines(pDisplay, wID, gc, xpt, 3, CoordModeOrigin);
1220 iVPos = (xwa.height - iVPos) >> 1;
1231 for(i1=0, iHPos = i2; pMenu && pMenu->
ppItems && i1 < pMenu->
nItems; i1++)
1254 if(strchr(szText,
'_'))
1257 strcpy(tbuf, szText);
1297 WBDrawString(pDisplay, wID, gc, iHPos, iVPos, szText, strlen(szText));
1301 xpt[0].x=iHPos + iU1 - 1;
1302 xpt[0].y=pSelf->
iY + pSelf->
iHeight - 1;
1303 xpt[1].x=iHPos + iU1 + iU2;
1306 WBDrawLines(pDisplay, wID, gc, xpt, 2, CoordModeOrigin);
1318 pSelf->
iWidth = iHPos - i2;
const char * CHGetHighlightForegroundColor(Display *pDisplay)
returns highlight foreground color
void WBSetWMProperties(Window wID, const char *szTitle, XSizeHints *pNormalHints, XWMHints *pWMHints, XClassHint *pClassHints)
assign standard WM (Window Manager) properties via XSetWMProperties
static __inline__ XStandardColormap * PXM_StandardColormapFromColormap(Display *pDisplay, Colormap colormap)
create temporary XStandardColormap from a Colormap
void PXM_RGBToYUV(int iR, int iG, int iB, int *piY, int *piU, int *piV)
Convert R, G, B values to Y, U, V with 0-255 range.
'window helper' main header file for the X11workbench Toolkit API
void WBAddMenuWindow(Window wID, Window wIDMenu)
Add a MENU WINDOW to a (frame) window.
void WBClearWindow(Window wID, WBGC gc)
'Paint' helper, erases background by painting the background color within the clipping region
#define WB_DEBUG_PRINT(L,...)
Preferred method of implementing conditional debug output.
int WBFontAscent(WB_FONTC pFont0)
Get the maximum character ascent from a WB_FONT.
bold font weight (mutually exclusive0
void WBCreateWindowDefaultGC(Window wID, unsigned long clrFG, unsigned long clrBG)
creates a default WBGC for a window
void PXM_YUVToRGB(int iY, int iU, int iV, int *piR, int *piG, int *piB)
Convert Y, U, V values to R, G, B with 0-255 range.
WB_FONT WBCopyFont(Display *pDisplay, WB_FONTC pOldFont)
make a copy of an existing font (best when assigning to a window)
Window WBLocateWindow(WBLocateWindowCallback callback, void *pData)
Locate a window by enumerating with a callback function.
const char * CHGetStaticBackgroundColor(Display *pDisplay)
returns background color for static elements
int WBWindowDispatch(Window wID, XEvent *pEvent)
Dispatches a window XEvent. May be called directly.
int WBPostPriorityEvent(Window wID, XEvent *pEvent)
Places a copy of the specified event at the end of the priority (internal) event queue.
void WBGetClientRect(Window wID, WB_RECT *pRect)
Returns the WB_RECT (rectangle) defined by the window's geometry, excluding the border area.
static __inline__ Display * WBGetDefaultDisplay(void)
Returns the default Display.
internal wrapper struct for X11 'geometry' definition
'configuration helper' main header file for the X11 Work Bench Toolkit API
void PXM_RGBToPixel(XStandardColormap *pMap, XColor *pColor)
Icon Registration for application 'large' and 'small' icons.
#define RGB255_TO_XCOLOR(R, G, B, X)
Simple RGB assignment to pixel, 0-255 RGB.
int WBSetFont(WBGC hGC, WB_FONTC pFont)
Assign font to a WBGC, a wrapper for XSetFont()
void PXM_PixelToRGB(XStandardColormap *pMap, XColor *pColor)
Convert the pixel menber of an XColor to RGB.
int WBDrawString(Display *display, Drawable d, WBGC gc, int x, int y, const char *string, int length)
wrapper for XDrawString()
int WBSetForeground(WBGC hGC, unsigned long foreground)
Assign foreground color, a wrapper for XSetForeground()
WB_FONT WBLoadFont(Display *pDisplay, const char *szFontName, int iFontSize, int iFlags)
load a WB_FONT font object based on a font name, size, and font flags
#define COPY_COLOR_NAME(X, Y, Z)
macro to get a color name or use default if it does not exist in settings
WB_FONTC WBQueryWindowFont(Window wID)
Returns the WB_FONT assigned to the window (may be NULL), not a copy.
const char * CHGetDisabledTextColor(Display *pDisplay)
returns 'disabled' (greyed) text color
#define RGB255_FROM_XCOLOR(X, R, G, B)
Simple RGB assignment from pixel, 0-255 RGB.
void WBInvalidateGeom(Window wID, const WB_GEOM *pGeom, int bPaintNow)
'Paint' helper, invalidates a geometry for asynchronous Expose event generation
int WBDrawLines(Display *display, Drawable d, WBGC gc, XPoint *points, int npoints, int mode)
Wrapper for XDrawLine()
unsigned long WBGetWindowFGColor(Window wID)
Returns the currently assigned foreground color.
const char * CHGetTextColor(Display *pDisplay)
returns text color
void * WBAlloc(int nSize)
High performance memory sub-allocator 'allocate'.
Window WBGetParentWindow(Window wID)
Returns the window's parent (or None if there is no parent)
#define END_XCALL_DEBUG_WRAPPER
wrapper macro for calls into the X11 library. This macro follows the call(s)
int WBSetFontNoCopy(WBGC hGC, WB_FONT pFont)
Assign font to a WBGC, a wrapper for XSetFont()
const char * CHGetHighlightBackgroundColor(Display *pDisplay)
returns highlight background color
#define WB_ERROR_PRINT(...)
Preferred method of implementing an 'error level' debug message for all subsystems.
void WBFree(void *pBuf)
High performance memory sub-allocator 'free'.
int WBPostEvent(Window wID, XEvent *pEvent)
Places a copy of the specified event at the end of the regular (internal) event queue.
void WBDestroyWindow(Window wID)
Destroy a window.
void WBSetWindowFont(Window wID, WB_FONTC pFont)
assigns the default WB_FONT object for a window
#define WB_MOUSE_INPUT_MASK
'Mouse' input mask, bit flag for window creation
void WBXlatCoordPoint(Window wIDSrc, int iXSrc, int iYSrc, Window wIDDest, int *piXDest, int *piYDest)
Translate X,Y point coordinates relative to a window.
Window WBCreateWindow(Display *pDisplay, Window wIDParent, WBWinEvent pProc, const char *szClass, int iX, int iY, int iWidth, int iHeight, int iBorder, int iIO, WB_UINT64 iFlags, XSetWindowAttributes *pXSWA)
Create a window.
#define WB_STANDARD_INPUT_MASK
'Standard' input mask, bit flag for window creation
WBGC WBBeginPaint(Window wID, XExposeEvent *pEvent, WB_GEOM *pgBounds)
'Paint' helper, creates a WBGC for use in updating the window in an Expose event handler
internal wrapper struct for 'rectangle' definition
int WBFontDescent(WB_FONTC pFont0)
Get the maximum character descent from a WB_FONT.
void WBSetWindowDefaultCursor(Window wID, int idStandardCursor)
Assigns a default cursor (by ID) to a window.
void WBRegisterMenuCallback(Window wID, WBWinEvent pMenuCallback)
(internal) Register a MENU callback for a window
int WBTextWidth(WB_FONTC pFont, const char *szText, int cbText)
Obtain the pixel width of specified text for a specified WB_FONT.
Display * WBGetWindowDisplay(Window wID)
returns the Display associated with a window
void WBSetWindowData(Window wID, int iIndex, void *pData)
assign 'data pointer' for a window and specified index value
#define BEGIN_XCALL_DEBUG_WRAPPER
wrapper macro for calls into the X11 library. This macro precedes the call(s)
void WBDumpFontInfo(const char *szFontName)
Dump debug information about fonts according to pSpec.
int WBFillRectangle(Display *display, Drawable d, WBGC gc, int x, int y, unsigned int width, unsigned int height)
Wrapper for XFillRectangle()
int WBSetBackground(WBGC hGC, unsigned long background)
Assign background color, a wrapper for XSetBackground()
An allocated structure containing XFontStruct, XFontInfo, and XftFont [as applicable] for a specified...
#define WB_KEYBOARD_INPUT_MASK
'Keyboard' input mask, bit flag for window creation
void WBEndPaint(Window wID, WBGC gc)
'Paint' helper, frees resources and marks the update region 'valid'
internal wrapper struct for GC with local cache
Atom aSET_FOCUS
dialog focus messages
int WBMapWindow(Display *pDisplay, Window wID)
Wrapper for XMapWindow, makes window visible.
Frame Window API functions and definitions.
#define WB_WARN_PRINT(...)
Preferred method of implementing a 'warning level' debug message for all subsystems.
void WBRemoveMenuWindow(Window wID, Window wIDMenu)
Remove (detach) the specified menu window from a (frame) window.
WB_FONTC WBQueryGCFont(WBGC gc)
return the WB_FONTC object that was assigned to a WBGC
WB_FONTC WBGetDefaultFont(void)
Returns a pointer to the default font WB_FONT for the default display. This is a shared resource; do ...