X11 Work Bench Toolkit  1.0
window_helper.h
Go to the documentation of this file.
1 
2 // _ _ _ _ _ //
3 // __ __(_) _ __ __| | ___ __ __ | |__ ___ | | _ __ ___ _ __ | |__ //
4 // \ \ /\ / /| || '_ \ / _` | / _ \\ \ /\ / / | '_ \ / _ \| || '_ \ / _ \| '__|| '_ \ //
5 // \ V V / | || | | || (_| || (_) |\ V V / | | | || __/| || |_) || __/| | _ | | | | //
6 // \_/\_/ |_||_| |_| \__,_| \___/ \_/\_/_____|_| |_| \___||_|| .__/ \___||_|(_)|_| |_| //
7 // |_____| |_| //
8 // //
9 // basic window creation and message handling //
10 // //
11 // Copyright (c) 2010-2016 by 'Big Bad Bombastic Bob' Frazier - all rights reserved. //
12 // You may use this file in any way you see fit provided that any copy or derived work //
13 // includes the above copyright notice. //
14 // //
15 // NOTE: 'WB' is for 'Work Bench', aka 'X11workbench Toolkit' //
16 // //
18 
19 /*****************************************************************************
20 
21  X11workbench - X11 programmer's 'work bench' application and toolkit
22  Copyright (c) 2010-2016 by Bob Frazier (aka 'Big Bad Bombastic Bob')
23  all rights reserved
24 
25  DISCLAIMER: The X11workbench application and toolkit software are supplied
26  'as-is', with no warranties, either implied or explicit.
27  Any claims to alleged functionality or features should be
28  considered 'preliminary', and might not function as advertised.
29 
30  BSD-like license:
31 
32  There is no restriction as to what you can do with this software, so long
33  as you include the above copyright notice and DISCLAIMER for any distributed
34  work that is equal to or derived from this one, along with this paragraph
35  that explains the terms of the license if the source is also being made
36  available. A "derived work" describes a work that uses a significant portion
37  of the source files or algorithms that are included with this one.
38  Specifically excluded from this are files that were generated by the software,
39  or anything that is included with the software that is part of another package
40  (such as files that were created or added during the 'configure' process).
41  Specifically included is the use of part or all of any of the X11 workbench
42  toolkit source or header files in your distributed application. If you do not
43  ship the source, the above copyright statement is still required to be placed
44  in a reasonably prominent place, such as documentation, splash screens, and/or
45  'about the application' dialog boxes.
46 
47  Use and distribution are in accordance with GPL, LGPL, and/or the above
48  BSD-like license. See COPYING and README files for more information.
49 
50 
51  Additional information at http://sourceforge.net/projects/X11workbench
52 
53 ******************************************************************************/
54 
55 
57 // - DOXYGEN RELATED STUFF - //
59 
74 // doxygen top-level stuff has been moved to doxy_comments.dox
75 
77 // - END DOXYGEN RELATED STUFF - //
79 
80 
81 
82 // window helpers - defines manager for callback procs, font, GC, and a generic event dispatcher
83 
84 #ifndef WINDOW_HELPER_H_INCLUDED
85 #define WINDOW_HELPER_H_INCLUDED
86 
87 // headers that must be included or I break
88 
89 #include <string.h> // for memset, mostly
90 
91 #include "platform_helper.h"
92 
93 #include "font_helper.h"
94 
95 #ifdef __cplusplus
96 extern "C" {
97 #endif // __cplusplus
98 
102 #define WB_DEFAULT_CURSOR XC_left_ptr
103 
106 #define WB_WAIT_CURSOR XC_watch /*XC_clock*/
107 
110 #define WB_DEFAULT_FONT "fixed"
111 
114 #define WB_DEFAULT_FONT_SIZE 13 /* override via settings */
115 
118 #define WINDOW_DATA_SIZE 4 /* size of a 'void *' array that stores per-window data */
119 
123 #define EVENT_ALL_MASK 0x01ffffffL /* 2^24 | 2^23 ... 2^0 - see X.h */
124 
125 
129 #define GCAll (GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth | \
130  GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle | GCFillRule | \
131  GCTile | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCFont | \
132  GCSubwindowMode | GCGraphicsExposures | GCClipXOrigin | GCClipYOrigin | \
133  GCClipMask | GCDashOffset | GCDashList | GCArcMode)
134 
135 
136 
137 // debug helpers (to be eliminated at some point)
138 
142 extern const char *sz_xcall_func;
146 extern int i_xcall_line;
151 #define BEGIN_XCALL_DEBUG_WRAPPER { const char *__szOldXCallFunc__ = sz_xcall_func; int __iOldXCallLine__ = i_xcall_line; sz_xcall_func = __FUNCTION__; i_xcall_line = __LINE__; {
152 
156 #define END_XCALL_DEBUG_WRAPPER } sz_xcall_func = __szOldXCallFunc__; i_xcall_line = __iOldXCallLine__; }
157 
158 
171 typedef int (* WBWinEvent)(Window wID, XEvent *pEvent);
183 typedef int (* WBAppEvent)(XEvent *pEvent);
184 
216 typedef struct _WBRect_
217 {
218  int left;
219  int top;
220  int right;
221  int bottom;
222 } WB_RECT;
223 
258 typedef struct _WBGeom_
259 {
260  int x;
261  int y;
262  unsigned int width;
263  unsigned int height;
264  unsigned int border;
265 } WB_GEOM;
266 
281 extern int bQuitFlag;
282 
283 
285 // initialization
287 
302 Display *WBInit(const char *szDisplayName);
303 
320 int WBInitDisplay(Display *pDisplay);
321 
340 int WBInitClipboardSystem(Display *pDisplay, const char *szDisplayName);
341 
351 void WBExit(void);
352 
360 void WBExitClipboardSystem(Display *pDisplay);
361 
373 Display *WBThreadInitDisplay(void);
374 
385 void WBThreadFreeDisplay(Display *pThreadDisplay);
386 
387 
402 int WBParseStandardArguments(int *pargc, char ***pargv, char ***penvp);
403 
409 void WBToolkitUsage(void);
410 
420 const char *GetStartupAppName(void);
421 
432 const char *GetStartupDisplayName(void);
433 
443 void GetStartupGeometry(WB_GEOM *pGeom);
452 int GetStartupMinMax(void);
453 
462 static __inline__ Colormap WBDefaultColormap(Display *pDisplay)
463 {
464  return DefaultColormap(pDisplay, DefaultScreen(pDisplay));
465 }
466 
482 void WBInitWindowAttributes(XSetWindowAttributes *pXSWA, unsigned long lBorderPixel,
483  unsigned long lBackgroundPixel, Colormap clrMap, int iBitGravity);
484 
500 void WBInitSizeHints(XSizeHints *pSH, Display *pDisplay, int iMinHeight, int iMinWidth);
501 
502 
504 // ____ _____ ____ _ _ ____ _ _ _____ _ ____ _____ ____ ____ //
505 // | _ \ | ____|| __ ) | | | | / ___| | | | || ____|| | | _ \ | ____|| _ \ / ___| //
506 // | | | || _| | _ \ | | | || | _ | |_| || _| | | | |_) || _| | |_) |\___ \ //
507 // | |_| || |___ | |_) || |_| || |_| | | _ || |___ | |___ | __/ | |___ | _ < ___) | //
508 // |____/ |_____||____/ \___/ \____| |_| |_||_____||_____||_| |_____||_| \_\|____/ //
509 // //
511 
512 
524 void WBSetDebugLevel(unsigned int iLevel);
525 
526 
541 #ifdef __GNUC__
542 static __inline__ unsigned int WBGetDebugLevel(void)
543 {
544 extern unsigned int iWBDebugLevel;
545 
546  return iWBDebugLevel;
547 }
548 #else // __GNUC__
549 unsigned int WBGetDebugLevel(void);
550 #endif // __GNUC__
551 
565 #ifdef __GNUC__
566 void WBDebugPrint(const char *pFmt, ...) __attribute__ ((format(printf, 1, 2)));
567 #else // __GNUC__
568 void WBDebugPrint(const char *pFmt, ...);
569 #endif // __GNUC__
570 
584 void WBDebugDump(const char *szTitle, void *pData, int cbData); // dump binary data
585 
597 void WBDebugDumpGC(Display *pDisplay, GC hGC);
598 
609 void WBDebugDumpRegion(Region hRgn, int bRotate);
610 
611 
622 void WBDebugDumpEvent(XEvent *pEvent);
623 
624 
625 
626 // NOTE: The debug code will be included when NO_DEBUG is *NOT* defined
627 
628 #ifdef NO_DEBUG /* assign this to disable debugging - most likely a -D in Makefile */
629 #define WB_DEBUG_PRINT(...)
630 #define WB_DEBUG_DUMP(L,X,Y,Z)
631 #define WB_IF_DEBUG_LEVEL(L) if(0) /* TODO: turn off the warning? */
632 #else // NO_DEBUG
633 
634 // NOTE: this macro is the preferred method of implementing debug output.
652 #define WB_DEBUG_PRINT(L, ...) \
653  if(WB_UNLIKELY((WBGetDebugLevel() & DebugLevel_MASK) >= ((L) & DebugLevel_MASK))) \
654  { \
655  if(!((L) & DebugSubSystem_MASK) || !(WBGetDebugLevel() & DebugSubSystem_MASK) \
656  || (((L) & WBGetDebugLevel()) & DebugSubSystem_MASK) != 0) \
657  { \
658  WBDebugPrint(__VA_ARGS__); \
659  } \
660  }
661 
679 #define WB_DEBUG_DUMP(L,X,Y,Z) \
680  if(WB_UNLIKELY((WBGetDebugLevel() & DebugLevel_MASK) >= ((L) & DebugLevel_MASK))) \
681  { \
682  if(!((L) & DebugSubSystem_MASK) || !(WBGetDebugLevel() & DebugSubSystem_MASK) \
683  || (((L) & WBGetDebugLevel()) & DebugSubSystem_MASK) != 0) \
684  { \
685  WBDebugDump(X,Y,Z); \
686  } \
687  }
688 
705 #define WB_IF_DEBUG_LEVEL(L) if(WB_UNLIKELY((WBGetDebugLevel() & DebugLevel_MASK) >= ((L) & DebugLevel_MASK)) && \
706  (!((L) & DebugSubSystem_MASK) || !(WBGetDebugLevel() & DebugSubSystem_MASK) \
707  || (((L) & WBGetDebugLevel()) & DebugSubSystem_MASK) != 0))
708 
709 #endif // NO_DEBUG
710 
711 
717 #define WB_WARN_PRINT(...) WB_DEBUG_PRINT(DebugLevel_WARN, __VA_ARGS__)
718 
724 #define WB_ERROR_PRINT(...) WB_DEBUG_PRINT(DebugLevel_ERROR, __VA_ARGS__)
725 
735 #define WB_WARN_DUMP(X,Y,Z) WB_DEBUG_DUMP(DebugLevel_WARN, X,Y,Z)
736 
746 #define WB_ERROR_DUMP(X,Y,Z) WB_DEBUG_DUMP(DebugLevel_ERROR, X,Y,Z)
747 
758 {
762 
763  // criteria for selecting debug output
772 
773  // next are subsystem masks for additional debugging
775  DebugSubSystem_RESTRICT = 0x80000000,
777  DebugSubSystem_Init = 0x00000008,
779  DebugSubSystem_Window = 0x00000020,
780  DebugSubSystem_Menu = 0x00000040,
781  DebugSubSystem_Event = 0x00000080,
782  DebugSubSystem_Dialog = 0x00000100,
784  DebugSubSystem_Frame = 0x00000400,
785  DebugSubSystem_Keyboard = 0x00000800,
786  DebugSubSystem_Mouse = 0x00001000,
787  DebugSubSystem_Font = 0x00002000,
788  DebugSubSystem_Settings = 0x00004000,
790  DebugSubSystem_Pixmap = 0x00010000,
791  DebugSubSystem_Expose = 0x00020000,
792 
794 };
795 
796 
797 
799 // ____ _____ _____ _ _ _ _ _____ ____ //
800 // | _ \ | ____|| ___|/ \ | | | || | |_ _|/ ___| //
801 // | | | || _| | |_ / _ \ | | | || | | | \___ \ //
802 // | |_| || |___ | _|/ ___ \| |_| || |___ | | ___) | //
803 // |____/ |_____||_| /_/ \_\\___/ |_____||_| |____/ //
804 // //
806 
823 static __inline__ Display * WBGetDefaultDisplay(void)
824 {
825  extern Display *pDefaultDisplay;
826  return pDefaultDisplay;
827 }
828 
841 XFontStruct *WBGetDefaultFont(void);
842 
856 XFontSet WBGetDefaultFontSet(Display *pDisplay);
857 
867 Window WBGetHiddenHelperWindow(void); // if you need "a window" for the default display, use this
868 
869 
870 
871 
873 // ____ _ ___ ____ _ _ _ _____ ___ __ __ ____ //
874 // / ___|| | / _ \ | __ ) / \ | | / \ |_ _|/ _ \ | \/ |/ ___| //
875 // | | _ | | | | | || _ \ / _ \ | | / _ \ | | | | | || |\/| |\___ \ //
876 // | |_| || |___| |_| || |_) |/ ___ \ | |___ / ___ \ | | | |_| || | | | ___) | //
877 // \____||_____|\___/ |____//_/ \_\|_____| /_/ \_\|_| \___/ |_| |_||____/ //
878 // //
880 
881 // global atoms (for convenience they are referenced directly via global variables)
882 
883 #if !defined(_WINDOW_HELPER_C_) && !defined(_CLIPBOARD_HELPER_C)
884  /* this declares the atoms 'const' outside of window_helper.c, and does NOT declare them in clipboard_helper.c */
885  /* These atoms are GLOBAL variables, assigned by the DEFAULT Display, and may not work for other threads. */
886 extern const Atom aMENU_COMMAND; // commands sent by menus via ClientMessage
887 extern const Atom aMENU_UI_COMMAND; // UI notification sent by menus to owning frame windows via ClientMessage using WBWindowDispatch
888 extern const Atom aRESIZE_NOTIFY; // notification of window re-size via ClientMessage
889 extern const Atom aDESTROY_NOTIFY; // notify parent that child is being destroyed
890 extern const Atom aCONTROL_NOTIFY; // dialog control and child window notification messages
891  // l[0] contains control ID or -1, l[1] is notify code, l[2] is window ID
892 extern const Atom aQUERY_CLOSE; // command sent by Client Message - return 0 if ok to close, 1 if not ok to close, -1 on error
893 extern const Atom aRECALC_LAYOUT; // notify window that it should re-calculate things like scrollbars and viewports
894 
895 extern const Atom aDLG_FOCUS; // dialog focus messages: l[0] is <,0,> for prev, 'set to', next. For 'set to' l[1] is control ID
896 extern const Atom aSET_FOCUS; // 'set focus' messages (send/post to application)
897 extern const Atom aWM_CHAR; // character notifications (generated by API; avoids key up/down handling)
898 extern const Atom aWM_TIMER; // timer notifications (generated by API)
899 extern const Atom aWM_POINTER; // pointer notifications (generated by API)
900 
901 // things used by window managers
902 extern const Atom aWM_PROTOCOLS; // WM supported protocols (see 'freedesktop.org' WM docs)
903 extern const Atom aWM_DELETE_WINDOW; // WM command to delete a window (a click on the 'x')
904 extern const Atom aWM_TAKE_FOCUS; // WM protocol (part of WM_PROTOCOLS spec, ICCCM, assoc with focus bit in WM_HINTS)
905 
906 // things used by fonts
907 extern const Atom aAVERAGE_WIDTH; // Average Character Width (font property)
908 
909 // things used by the clipboard
910 extern const Atom aCLIPBOARD; // Atom for 'CLIPBOARD'
911 extern const Atom aPRIMARY; // Atom for 'PRIMARY'
912 extern const Atom aSECONDARY; // Atom for 'SECONDARY'
913 extern const Atom aMANAGER; // Atom for 'MANAGER'
914 extern const Atom aTARGET; // Atom for 'TARGET'
915 extern const Atom aINCR; // Atom for 'INCR' (incremental transfers)
916 extern const Atom aWINDOW; // Atom for 'WINDOW'
917 extern const Atom aBITMAP; // Atom for 'BITMAP'
918 extern const Atom aDRAWABLE; // Atom for 'DRAWABLE'
919 extern const Atom aCOLORMAP; // Atom for 'COLORMAP'
920 extern const Atom aPIXEL; // Atom for 'PIXEL'
921 extern const Atom aPIXMAP; // Atom for 'PIXMAP'
922 extern const Atom aTEXT; // Atom for 'TEXT'
923 extern const Atom aSTRING; // Atom for 'STRING'
924 extern const Atom aUTF8_STRING; // Atom for 'UTF8_STRING'
925 extern const Atom aC_STRING; // Atom for 'C_STRING'
926 extern const Atom aCOMPOUND_TEXT; // Atom for 'COMPOUND_TEXT'
927 extern const Atom aTARGETS; // Atom for 'TARGETS'
928 extern const Atom aMULTIPLE; // Atom for 'MULTIPLE'
929 extern const Atom aTIMESTAMP; // Atom for 'TIMESTAMP'
930 extern const Atom aNULL; // Atom for 'NULL'
931 #endif // !_WINDOW_HELPER_C, !_CLIPBOARD_HELPER_C
932 
933 
934 
936 // ____ ___ ____ _____ _ ____ ___ //
937 // / ___|/ _ \ | _ \ | ____| / \ | _ \|_ _| //
938 // | | | | | || |_) || _| / _ \ | |_) || | //
939 // | |___| |_| || _ < | |___ / ___ \ | __/ | | //
940 // \____|\___/ |_| \_\|_____| /_/ \_\|_| |___| //
941 // //
943 
984 #define WB_STANDARD_INPUT_MASK (FocusChangeMask | PropertyChangeMask | ExposureMask | StructureNotifyMask | VisibilityChangeMask | SubstructureNotifyMask)
985 
992 #define WB_KEYBOARD_INPUT_MASK (KeyPressMask | KeyReleaseMask)
993 
1000 #define WB_MOUSE_INPUT_MASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | LeaveWindowMask)
1001 
1002 
1010 {
1011  // must be ONLY ONE of the items below
1012  WMPropertiesWindowType_TypeMask = 0x3f,
1013  WMPropertiesWindowType_Normal = 0,
1014  WMPropertiesWindowType_Desktop = 1,
1015  WMPropertiesWindowType_Dock = 2,
1016  WMPropertiesWindowType_ToolBar = 3,
1017  WMPropertiesWindowType_Menu = 4,
1018  WMPropertiesWindowType_Utility = 5,
1019  WMPropertiesWindowType_Splash = 6,
1020  WMPropertiesWindowType_Dialog = 7,
1021  WMPropertiesWindowType_DropDownMenu = 8,
1022  WMPropertiesWindowType_PopupMenu = 9,
1023  WMPropertiesWindowType_ToolTip = 10,
1024  WMPropertiesWindowType_Notification = 11,
1025  WMPropertiesWindowType_Combo = 12,
1026  WMPropertiesWindowType_Drag_N_Drop = 13,
1027  WMPropertiesWindowType_Reserved14 = 14,
1028  WMPropertiesWindowType_Reserved15 = 15,
1029 
1030 
1031  // may be A COMBINATION of the items below
1032  WMPropertiesWindowType_StateMask = 0xfffC0,
1033 
1034  WMPropertiesWindowType_NoState = 0,
1035  WMPropertiesWindowType_Modal = 0x00040,
1036  WMPropertiesWindowType_Sticky = 0x00080,
1037  WMPropertiesWindowType_VMax = 0x00100,
1038  WMPropertiesWindowType_HMax = 0x00200,
1039  WMPropertiesWindowType_FullScreen = 0x00400,
1040  WMPropertiesWindowType_Hidden = 0x00800,
1041  WMPropertiesWindowType_Shaded = 0x01000,
1042  WMPropertiesWindowType_SkipTaskbar = 0x02000,
1043  WMPropertiesWindowType_SkipPager = 0x04000,
1044  WMPropertiesWindowType_Above = 0x08000,
1045  WMPropertiesWindowType_Below = 0x10000,
1046  WMPropertiesWindowType_Focused = 0x20000,
1047  WMPropertiesWindowType_DemandsAttention = 0x40000,
1048  WMPropertiesWindowType_Reserved80000 = 0x80000,
1049 
1050 
1051  // TODO: other stuff
1052 
1053  WMPropertiesWindowType_Max = 0x80000000
1054 };
1055 
1063 {
1064  // The following flags indicate WM_PROTOCOLS support
1065  // Assigning these directly can have unexpected consequences
1066  WMPropertiesWMProtocols_Mask = 0xff,
1067  WMPropertiesWMProtocols_None = 0x0, // the default
1068  WMPropertiesWMProtocols_DeleteWindow = 0x01,
1069  WMPropertiesWMProtocols_Reserved2 = 0x02,
1070  WMPropertiesWMProtocols_Reserved3 = 0x04,
1071  WMPropertiesWMProtocols_Reserved4 = 0x08,
1072  WMPropertiesWMProtocols_Reserved5 = 0x10,
1073  WMPropertiesWMProtocols_Reserved6 = 0x20,
1074  WMPropertiesWMProtocols_Reserved7 = 0x40,
1075  WMPropertiesWMProtocols_Reserved8 = 0x80,
1076 };
1077 
1078 
1079 
1105 Window WBCreateWindow(Display *pDisplay, Window wIDParent,
1106  WBWinEvent pProc, const char *szClass,
1107  int iX, int iY, int iWidth, int iHeight, int iBorder, int iIO,
1108  int iFlags, XSetWindowAttributes *pXSWA);
1109 
1117 void WBDestroyWindow(Window wID);
1118 
1129 Window WBGetApplicationWindow(void);
1130 
1143 void WBSetApplicationWindow(Window wID);
1144 
1150 int WBDefault(Window wID, XEvent *pEvent);
1151 
1157 int WBAppDefault(XEvent *pEvent);
1158 
1168 void WBRegisterAppCallback(WBAppEvent pCallback);
1169 
1176 
1182 void WBRegisterWindowCallback(Window wID, WBWinEvent pCallback);
1183 
1189 void WBUnregisterWindowCallback(Window wID);
1190 
1202 void WBSetWMProperties(Window wID, const char *szTitle, XSizeHints *pNormalHints,
1203  XWMHints *pWMHints, XClassHint *pClassHints);
1212 void WBSetWindowTitle(Window wID, const char *szTitle);
1213 
1225 void WBSetWMPropertiesWindowType(Window wID, enum WMPropertiesWindowType wmProp);
1226 
1239 void WBChangeWMPropertiesWindowType(Window wID, enum WMPropertiesWindowType wmPropSet, enum WMPropertiesWindowType wmChangeMask);
1240 
1241 
1253 
1267 void WBSetWMProtocols(Window wID, Atom aProperty, ...);
1268 
1269 
1279 typedef int (*WBLocateWindowCallback)(Window wID, void *pData);
1280 
1300 Window WBLocateWindow(WBLocateWindowCallback callback, void *pData);
1301 
1312 void WBSetInputFocus(Window wID);
1313 
1322 Display * WBGetWindowDisplay(Window wID);
1323 
1332 void WBSetWindowIcon(Window wID, int idIcon);
1333 
1342 void WBSetWindowFontStruct(Window wID, XFontStruct *pFontStruct);
1343 
1352 void WBSetWindowFontSet(Window wID, XFontSet fontSet);
1353 
1362 void WBSetWindowDefaultCursor(Window wID, int idStandardCursor);
1363 
1372 int WBGetWindowDefaultCursor(Window wID);
1373 
1383 void WBCreateWindowDefaultGC(Window wID, unsigned long clrFG, unsigned long clrBG);
1384 
1393 void WBSetWindowDefaultGC(Window wID, GC hGC);
1394 
1403 GC WBGetWindowCopyGC(Window wID);
1404 
1417 #define WBGetWindowCopyGC2(wID, gcSrc) WBCopyDrawableGC(WBGetWindowDisplay(wID), wID, gcSrc)
1418 
1432 GC WBCopyDrawableGC(Display *pDisplay, Drawable dw, GC gcSrc);
1433 
1448 XFontStruct * WBGetGCFont(Display *pDisplay, GC gc);
1449 
1459 void WBSetWindowData(Window wID, int iIndex, void *pData);
1460 
1468 void WBBeginWaitCursor(Window wID);
1469 
1477 void WBEndWaitCursor(Window wID);
1478 
1487 void WBSetWindowCursor(Window wID, int idCursor);
1488 
1496 void WBRestoreDefaultCursor(Window wID);
1497 
1514 GC WBGetWindowDefaultGC(Window wID);
1515 
1524 XFontStruct *WBGetWindowFontStruct(Window wID);
1525 
1534 XFontSet WBGetWindowFontSet(Window wID);
1535 
1544 unsigned long WBGetWindowFGColor(Window wID);
1545 
1554 unsigned long WBGetWindowBGColor(Window wID);
1555 
1568 unsigned long WBGetGCFGColor(Display *pDisplay, GC gc);
1569 
1582 unsigned long WBGetGCBGColor(Display *pDisplay, GC gc);
1583 
1604 void WBDefaultStandardColormap(Display *pDisplay, XStandardColormap *pMap);
1605 
1619 void WBSetWindowClassName(Window wID, const char *szClassName);
1620 
1633 const char *WBGetWindowClassName(Window wID);
1634 
1651 void *WBGetWindowData(Window wID, int iIndex);
1652 
1661 void WBGetWindowGeom(Window wID, WB_GEOM *pGeom);
1662 
1671 void WBGetWindowGeom2(Window wID, WB_GEOM *pGeom);
1672 
1673 
1691 void WBGetWindowGeom0(Window wID, WB_GEOM *pGeom); // absolute window geometry (from latest notification)
1692 
1701 void WBGetWindowRect(Window wID, WB_RECT *pRect);
1702 
1711 void WBGetClientRect(Window wID, WB_RECT *pRect);
1712 
1713 
1722 Window WBGetParentWindow(Window wID);
1723 
1724 
1739 void WBSetParentWindow(Window wID, Window wIDParent);
1740 
1756 int WBReparentWindow(Window wID, Window wIDParent, int iX, int iY); // keeps internal info up to date
1757 
1772 int WBIsChildWindow(Window wIDParent, Window wIDChild); // non-zero if 'wIDParent' is in a parent relationship with 'wIDChild'
1773 
1782 #define WBPointInRect(X,Y,R) ((X) >= (R).left && (X) < (R).right && (Y) >= (R).top && (Y) < (R).bottom)
1783 
1791 #define WBPointInGeom(X,Y,G) ((X) >= (G).x && (X) < ((G).x + (G).width) && (Y) >= (G).y && (Y) < ((G).y + (G).height))
1792 
1799 #define WBRectOverlapped(R1,R2) \
1800  ((((R1).left >= (R2).left && (R1).left < (R2).right) || \
1801  ((R2).left >= (R1).left && (R2).left < (R1).right)) && \
1802  (((R1).top >= (R2).top && (R1).top < (R2).bottom) || \
1803  ((R2).top >= (R1).top && (R2).top < (R1).bottom)))
1804 
1811 #define WBGeomOverlapped(G1,G2) \
1812  ((((G1).x >= (G2).x && (G1).x < (G2).x + (G2).width) || \
1813  ((G2).x >= (G1).x && (G2).x < (G1).x + (G1).width)) && \
1814  (((G1).y >= (G2).y && (G1).y < (G2).y + (G2).height) || \
1815  ((G2).y >= (G1).y && (G2).y < (G1).y + (G1).height)))
1816 
1834 void WBXlatCoordPoint(Window wIDSrc, int iXSrc, int iYSrc, Window wIDDest, int *piXDest, int *piYDest);
1835 
1851 void WBXlatCoordGeom(Window wIDSrc, const WB_GEOM *pGeomSrc, Window wIDDest, WB_GEOM *pGeomDest);
1852 
1868 void WBXlatCoordRect(Window wIDSrc, const WB_RECT *pRectSrc, Window wIDDest, WB_RECT *pRectDest);
1869 
1885 int WBPointInWindow(Window wIDRef, int iX, int iY, Window wIDQuery);
1886 
1887 // keyboard translation helpers
1888 
1892 #define WB_KEYEVENT_KEYSYM 8 /* bit flags for 'piAltCtrlShift' below */
1893 
1897 #define WB_KEYEVENT_ALT 4
1898 
1902 #define WB_KEYEVENT_CTRL 2
1903 
1907 #define WB_KEYEVENT_SHIFT 1
1908 
1912 #define WB_KEYEVENT_ACSMASK 7
1913 
1914 
1935 int WBKeyEventProcessKey(const XKeyEvent *pEvent, char *pBuf, int *pcbLen, int *piAltCtrlShift);
1936  // NOTE: WM_CHAR notification messages (related to WBKeyEventProcessKey)
1937  // message_type == aWM_CHAR
1938  // data.l[0] is return frmo WBKeyEventProcessKey
1939  // data.l[1] is *piAltCtrlShift from WBKeyEventProcessKey
1940  // data.l[2] is number of characters decoded into data.l[3..4]
1941  // data.l[3..4] (as char[]) is decode buffer (at least 8 chars long, possibly 16 for 64-bit)
1942 
1943 
1944 
1945 // pointer event definitions - WM_POINTER
1946 // data.l[0] is notification code (below)
1947 // data.l[1] is bitmap of mouse button state (button 1 is bit 0, button 2 is bit 1, etc.)
1948 // data.l[2] is 'WB_KEYEVENT_' mask for CTRL+ALT+SHIFT
1949 // data.l[3] is translated X coordinate
1950 // data.l[4] is translated Y coordinate
1951 
1955 #define WB_POINTER_UNSPECIFIED 0 /* possible motion or state-change notifications */
1956 
1960 #define WB_POINTER_CLICK 1
1961 
1965 #define WB_POINTER_DBLCLICK 2
1966 
1970 #define WB_POINTER_DRAG 3 /* window proc returns window ID to support drag/drop */
1971 
1975 #define WB_POINTER_DROP 4 /* may not happen if drag is canceled */
1976 
1980 #define WB_POINTER_MOVE 5 /* motion notify while dragging */
1981 
1985 #define WB_POINTER_CANCEL 6 /* reservedly any kind of cancellation, but for now, 'drag cancel' */
1986 
1990 #define WB_POINTER_SCROLLUP 7 /* scroll event, mouse button 4 */
1991 
1995 #define WB_POINTER_SCROLLDOWN 8 /* scroll event, mouse button 5 */
1996 
2000 #define WB_POINTER_BUTTON1 1 /* these are bitmasks */
2001 
2004 #define WB_POINTER_BUTTON2 2
2005 
2008 #define WB_POINTER_BUTTON3 4
2009 
2012 #define WB_POINTER_BUTTON4 8
2013 
2016 #define WB_POINTER_BUTTON5 16
2017 
2018 // (you can add multiple menus to multiple windows)
2024 void WBRegisterMenuCallback(Window wID, WBWinEvent pCallback);
2025 
2034 void WBAddMenuWindow(Window wID, Window wIDMenu);
2043 Window WBGetMenuWindow(Window wID); // returns ID of menu window assigned by above (one only)
2052 void WBRemoveMenuWindow(Window wID, Window wIDMenu);
2053 
2068 int WBIsValid(Display *pDisplay, Window wID);
2069 
2070 
2071 
2073 // _____ __ __ _____ _ _ _____ ____ //
2074 // | ____|\ \ / /| ____|| \ | ||_ _|/ ___| //
2075 // | _| \ \ / / | _| | \| | | | \___ \ //
2076 // | |___ \ V / | |___ | |\ | | | ___) | //
2077 // |_____| \_/ |_____||_| \_| |_| |____/ //
2078 // //
2080 
2081 // message loop helpers
2082 
2094 Time WBGetLastEventTime(void);
2095 
2096 
2155 int WBCheckGetEvent(Display *pDisplay, XEvent *pEvent);
2156 
2170 void WBWaitForEvent(Display *pDisplay);
2171 
2172 
2184 void WBDispatch(XEvent *pEvent);
2185 
2197 int WBAppDispatch(XEvent *pEvent);
2198 
2214 int WBWindowDispatch(Window wID, XEvent *pEvent);
2215 
2228 const char * WBEventName(int iEventID);
2229 
2247 int WBShowModal(Window wID, int bMenuSplashFlag); // modal window - returns 'EndModal' value or -1 on error
2248 
2260 void WBEndModal(Window wID, int iReturn);
2261 
2262 // client-side message queue (avoids XSendEvent)
2263 // to send a message directly use WBAppDispatch and WBWindowDispatch
2264 
2283 int WBNextEvent(Display *pDisplay, XEvent *pEvent);
2284 
2301 int WBPostEvent(Window wID, XEvent *pEvent);
2302 
2316 int WBPostPriorityEvent(Window wID, XEvent *pEvent); // like above but it goes at the beginning of the queue
2317 
2332 void WBPostDelayedEvent(XEvent *pEvent, unsigned int nDelay);
2333 
2346 int WBPostAppEvent(XEvent *pEvent);
2347 
2367 void WBPostDelayedSetFocusAppEvent(Display *pDisplay, Window wID, Window wIDFrom, unsigned int nDelay);
2368 
2385 void WBProcessExposeEvent(XExposeEvent *pEvent); // paint optimization
2386 
2387 
2388 
2390 // //
2391 // _ _ ___ _ _ _ //
2392 // | | | ||_ _| | | | | ___ | | _ __ ___ _ __ ___ //
2393 // | | | | | | | |_| | / _ \| || '_ \ / _ \| '__|/ __| //
2394 // | |_| | | | | _ || __/| || |_) || __/| | \__ \ //
2395 // \___/ |___| |_| |_| \___||_|| .__/ \___||_| |___/ //
2396 // |_| //
2397 // //
2399 
2400 
2417 void WBMouseCancel(Display *pDisplay, Window wID);
2418 
2419 
2420 
2421 
2423 // ____ _ ___ ____ ____ ___ _ ____ ____ //
2424 // / ___| | |_ _| _ \| __ ) / _ \ / \ | _ \| _ \ //
2425 // | | | | | || |_) | _ \| | | |/ _ \ | |_) | | | | //
2426 // | |___| |___ | || __/| |_) | |_| / ___ \| _ <| |_| | //
2427 // \____|_____|___|_| |____/ \___/_/ \_\_| \_\____/ //
2428 // //
2430 
2459 void * WBGetClipboardData(Display *pDisplay, Atom *paType, int *piFormat, unsigned long *pnData);
2460 
2476 int WBSetClipboardData(Display *pDisplay, Atom aType, int iFormat, const void *pData, unsigned long nData);
2477 
2478 
2479 // lower level functions for 'Selections'
2480 
2499 void * WBGetSelectionData(Display *pDisplay, Atom aSelection, Atom *paType, int *piFormat, unsigned long *pnData);
2500 
2501 
2518 int WBSetSelectionData(Display *pDisplay, Atom aSelection, Atom aType, int iFormat, const void *pData, unsigned long nData);
2519 
2520 
2521 
2522 
2524 // _____ __ __ ____ ___ ____ _ _ ____ _____ //
2525 // | ____|\ \/ /| _ \ / _ \ / ___| | | | || _ \ | ____| //
2526 // | _| \ / | |_) || | | |\___ \ | | | || |_) || _| //
2527 // | |___ / \ | __/ | |_| | ___) || |_| || _ < | |___ //
2528 // |_____|/_/\_\|_| \___/ |____/ \___/ |_| \_\|_____| //
2529 // //
2531 
2586 int WBMapWindow(Display *pDisplay, Window wID);
2599 int WBMapRaised(Display *pDisplay, Window wID);
2612 int WBUnmapWindow(Display *pDisplay, Window wID);
2613 
2628 int WBIsMapped(Display *pDisplay, Window wID); // non-zero if mapped, zero otherwise
2629  // NOTE: this only works for windows that have been registered with a callback
2630 
2631 
2632 // paint helpers (working in conjunction with 'WBProcessExposeEvent')
2633 
2649 void WBInvalidateGeom(Window wID, const WB_GEOM *pGeom, int bPaintFlag);
2665 void WBInvalidateRegion(Window wID, Region rgn, int bPaintFlag);
2679 void WBValidateGeom(Window wID, const WB_GEOM *pGeom);
2693 void WBValidateRegion(Window wID, Region rgn);
2694 
2706 Region WBGetInvalidRegion(Window wID);
2707 
2721 Region WBGetPaintRegion(Window wID);
2722 
2734 Region WBRectToRegion(const WB_RECT *pRect);
2735 
2747 Region WBGeomToRegion(const WB_GEOM *pGeom);
2748 
2759 void WBUpdateWindow(Window wID); // posts an expose event for the specified window
2760 
2772 void WBUpdateWindowImmediately(Window wID); // sends expose event synchronously (can cause recursion)
2773 
2793 GC WBBeginPaint(Window wID, XExposeEvent *pEvent, WB_GEOM *pgRet); // GC has invalid region assigned
2794 
2811 GC WBBeginPaintGeom(Window wID, WB_GEOM *pgBounds); // GC has invalid region assigned
2812 
2824 void WBEndPaint(Window wID, GC gc); // frees the 'paint GC' and also resets the invalid region
2825 
2837 void WBClearWindow(Window wID, GC gc);
2838 
2839 
2840 // RECT versions (as inline)
2841 
2857 static __inline__ void WBInvalidateRect(Window wID, const WB_RECT *pRCT, int bPaintFlag)
2858 {
2859  WB_GEOM geom;
2860 
2861  if(!pRCT)
2862  {
2863  WBInvalidateGeom(wID, NULL, bPaintFlag);
2864  return;
2865  }
2866 
2867  geom.x = pRCT->left;
2868  geom.y = pRCT->top;
2869  geom.width = pRCT->right - pRCT->left;
2870  geom.height = pRCT->bottom - pRCT->top;
2871  geom.border = 0;
2872 
2873  WBInvalidateGeom(wID, &geom, bPaintFlag);
2874 }
2875 
2889 static __inline__ void WBValidateRect(Window wID, WB_RECT *pRCT)
2890 {
2891  WB_GEOM geom;
2892 
2893  if(!pRCT)
2894  {
2895  WBValidateGeom(wID, NULL);
2896  return;
2897  }
2898 
2899  geom.x = pRCT->left;
2900  geom.y = pRCT->top;
2901  geom.width = pRCT->right - pRCT->left;
2902  geom.height = pRCT->bottom - pRCT->top;
2903  geom.border = 0;
2904 
2905  WBValidateGeom(wID, &geom);
2906 }
2907 
2908 
2909 
2911 // _____ ___ __ __ _____ ____ ____ //
2912 // |_ _||_ _|| \/ || ____|| _ \ / ___| //
2913 // | | | | | |\/| || _| | |_) |\___ \ //
2914 // | | | | | | | || |___ | _ < ___) | //
2915 // |_| |___||_| |_||_____||_| \_\|____/ //
2916 // //
2918 
2946 WB_UINT64 WBGetTimeIndex(void); // returns current 'time index' (in microseconds) which never wraps around
2947  // NOTE: it is derived from the 'gettimeofday' call on BSD, Linux, etc.
2948 
2964 int CreateTimer(Display *pDisplay, Window wID, unsigned long lInterval, long lID, int iPeriodic);
2965  // NOTE: 'iPeriodic' non-zero for periodic, zero for one-shot. 'lInterval' is in microseconds
2966  // Assign 'lID' to a unique value for the specified pDisplay and wID
2967 
2980 void DeleteTimer(Display *pDisplay, Window wID, long lID); // deletes entry with matching Display, Window, ID
2981 
2982 
2983 
2984 // ****************************************************
2985 //
2986 // E R R O R H A N D L I N G
2987 //
2988 // ****************************************************
2989 
3014 typedef struct __WB_ERROR_INFO__
3015 {
3016  Display *pDisplay;
3017  const char *pFunc;
3018  int iLine;
3019  unsigned long serial;
3024 } WB_ERROR_INFO;
3025 
3026 
3027 
3037 static __inline__ void WBSupressErrorOutput(void)
3038 {
3039 extern int bIgnoreXErrors;
3040 
3041  bIgnoreXErrors++;
3042 }
3043 
3053 static __inline__ void WBAllowErrorOutput(void)
3054 {
3055 extern int bIgnoreXErrors;
3056 
3057  if(bIgnoreXErrors > 0)
3058  {
3059  bIgnoreXErrors--;
3060  }
3061  else
3062  {
3063  bIgnoreXErrors = 0;
3064  }
3065 }
3066 
3067 
3073 void WBErrorClear(void);
3074 
3086 int WBErrorCheck(void);
3087 
3100 int WBErrorCheckRetry(void);
3101 
3114 const WB_ERROR_INFO * WBGetLastError(void);
3115 
3116 
3117 
3118 #ifdef __cplusplus
3119 };
3120 #endif // __cplusplus
3121 
3122 #endif // WINDOW_HELPER_H_INCLUDED
3123