home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xlib_private.h < prev    next >
C/C++ Source or Header  |  2001-05-21  |  17KB  |  549 lines

  1.  
  2. #ifndef XLIB_PRIVATE
  3. #define XLIB_PRIVATE
  4.  
  5. #include <stdlib.h>
  6. #include <ctype.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <strings.h>
  10. #include <limits.h>
  11. #include <unistd.h>
  12. #include <stdarg.h>
  13. #include <sys/types.h>
  14. #include <sys/time.h>
  15. #include <sys/signal.h>
  16. #include <io.h>
  17.  
  18. #include <pthread.h>
  19.  
  20. #define INCL_BASE
  21. #define INCL_WIN
  22. #define INCL_GPI
  23. #define INCL_WINATOM
  24. #include <os2.h>
  25.  
  26. /*#define XTHREADS */
  27. #include "X.h"
  28. #include "Xlib.h"
  29. #include "X11/Xatom.h"
  30. #include "X11/Xutil.h"
  31. #include "X11/Xresource.h"
  32. #include "X11/Xproto.h"
  33.  
  34. /*
  35.  * This structure is private to the library.
  36.  */
  37. typedef struct _XFreeFuncs {
  38.     void (*atoms)();            /* _XFreeAtomTable */
  39.     int (*modifiermap)();       /* XFreeModifierMap */
  40.     void (*key_bindings)();     /* _XFreeKeyBindings */
  41.     void (*context_db)();       /* _XFreeContextDB */
  42.     void (*defaultCCCs)();      /* _XcmsFreeDefaultCCCs */
  43.     void (*clientCmaps)();      /* _XcmsFreeClientCmaps */
  44.     void (*intensityMaps)();    /* _XcmsFreeIntensityMaps */
  45.     void (*im_filters)();       /* _XFreeIMFilters */
  46.     void (*xkb)();              /* _XkbFreeInfo */
  47. } _XFreeFuncRec;
  48.  
  49. typedef struct _XExten {        /* private to extension mechanism */
  50.         struct _XExten *next;   /* next in list */
  51.         XExtCodes codes;        /* public information, all extension told */
  52.         int (*create_GC)();     /* routine to call when GC created */
  53.         int (*copy_GC)();       /* routine to call when GC copied */
  54.         int (*flush_GC)();      /* routine to call when GC flushed */
  55.         int (*free_GC)();       /* routine to call when GC freed */
  56.         int (*create_Font)();   /* routine to call when Font created */
  57.         int (*free_Font)();     /* routine to call when Font freed */
  58.         int (*close_display)(); /* routine to call when connection closed */
  59.         int (*error)();         /* who to call when an error occurs */
  60.         char *(*error_string)();  /* routine to supply error string */
  61.         char *name;             /* name of this extension */
  62.         void (*error_values)(); /* routine to supply error values */
  63.         void (*before_flush)(); /* routine to call when sending data */
  64.         struct _XExten *next_flush; /* next in list of those with flushes */
  65. } _XExtension;
  66.  
  67. #define UM_CreateWindow         (WM_USER+0)
  68. #define UM_SetWindowPos         (WM_USER+1)
  69. #define UM_DestroyWindow        (WM_USER+2)
  70. #define UM_CreateGC             (WM_USER+3)
  71. #define UM_ChangeProperty       (WM_USER+4)
  72. #define UM_GetWinProperty       (WM_USER+5)
  73. #define UM_ReparentWindow       (WM_USER+6)
  74.  
  75. #define QWP_WINATTRIB           (QWL_USER+0)
  76. #define QWP_FRAMEHWND           (QWL_USER+4)
  77.  
  78. #define GC_NOPATH               (0)
  79. #define GC_STROKEPATH           (1)
  80. #define GC_FILLPATH             (2)
  81. #define GC_AREAFILL             (3)
  82. #define GC_FLUSHPATH            (4)
  83.  
  84. /*
  85.  * Display flags
  86.  */
  87. #define XlibDisplayIOError      (1L << 0)
  88. #define XlibDisplayClosing      (1L << 1)
  89. #define XlibDisplayNoXkb        (1L << 2)
  90. #define XlibDisplayPrivSync     (1L << 3)
  91. #define XlibDisplayProcConni    (1L << 4) /* in _XProcessInternalConnection */
  92. #define XlibDisplayReadEvents   (1L << 5) /* in _XReadEvents */
  93. #define XlibDisplayReply        (1L << 5) /* in _XReply */
  94. #define XlibDisplayWriting      (1L << 6) /* in _XFlushInt, _XSend */
  95.  
  96. /* For _XSnprintf */
  97. #define HAS_SNPRINTF
  98. #define LIBX11
  99.  
  100. struct Xlib_Font_st;
  101. struct Xlib_Pixmap_st;
  102.  
  103. typedef enum {
  104.         PMATM_NULL, PMATM_FONT, PMATM_BITMAP
  105. }       PMAtmType;
  106.  
  107. typedef struct {
  108.         PMAtmType type;
  109.         union {
  110.                 struct Xlib_Font_st *font;
  111.                 struct Xlib_Pixmap_st *pixmap;
  112.         } data;
  113. }       PMAtoms;
  114.  
  115. typedef struct {
  116.         USHORT  cb;
  117.         GC currentGC;
  118.         HDC hdc;
  119.         HPS hps;
  120.         PMAtoms *pmatoms;
  121.         void *reserved;
  122.         XWindowAttributes winattrib;
  123.         XEvent  *lastexpose, *lastconfigure;
  124.         unsigned int prevkeycode, prevkeystate;
  125.         Pixmap background_pixmap;       /* background or None or ParentRelative */
  126.         unsigned long background_pixel; /* background pixel */
  127.         Cursor cursor;
  128.         Bool delete_window_notify;
  129.         char *wm_name, *wm_iconname, *wm_class, *wm_locale;
  130.         XSizeHints *sizehints;
  131.         XWMHints *hints;
  132.         Window wm_client_leader;
  133. }       WinAttribData;
  134.  
  135. typedef struct Xlib_Pixmap_st {         /* First 5 elements same as WinAttribData */
  136.         USHORT  cb;
  137.         GC currentGC;
  138.         HDC hdc;
  139.         HPS hps;
  140.         PMAtoms *pmatoms;
  141.         struct Xlib_Pixmap_st **pixatoms;
  142.         HBITMAP hbm;
  143.         int width, height;
  144.         Colormap colormap;
  145. } Xlib_Pixmap;
  146.  
  147. typedef struct {
  148.         XExtData *ext_data;     /* hook for extension to hang data */
  149.         HPS gid;                /* Presentation space handle */
  150.         HRGN cliprgn;           /* clipmask region */
  151.         XGCValues values;       /* shadow structure of values */
  152.         WinAttribData *winattrib;
  153.         Xlib_Pixmap *pixmap;
  154.         int path;
  155.         POINTL cp;
  156. } Xlib_GC;
  157.  
  158. typedef struct Xlib_Font_st {
  159.         FATTRS fattrs;
  160.         SIZEF  sizef;
  161.         int    psmode;
  162.         int    descender;
  163.         struct Xlib_Pixmap_st **pixatoms;
  164. } Xlib_Font;
  165.  
  166. typedef struct {
  167.         HWND    hwndParent;
  168.         ULONG   flStyle;
  169.         PSZ     pszTitle;
  170.         LONG    x;
  171.         LONG    y;
  172.         LONG    cx;
  173.         LONG    cy;
  174.         WinAttribData *winattrib;
  175.         ULONG   frameStyle;
  176. } Xlib_CreateWindow;
  177.  
  178. typedef struct {
  179.         HWND    hwnd;
  180.         HWND    hwndInsertBehind;
  181.         LONG    x;
  182.         LONG    y;
  183.         LONG    cx;
  184.         LONG    cy;
  185.         ULONG   fl;
  186. } Xlib_SetWindowPos;
  187.  
  188. typedef struct {
  189.         Display*        display;
  190.         Window          w;
  191.         Atom            property, type;
  192.         int             format, mode;
  193.         unsigned char*  data;
  194.         int             nelements;
  195. } Xlib_ChangeProperty;
  196.  
  197. typedef struct {
  198.         Display*        display;
  199.         Window          w;
  200.         Atom            property;
  201.         long            long_offset, long_length;
  202.         Bool            delete;
  203.         Atom            req_type, *actual_type_return;
  204.         int*            actual_format_return;
  205.         unsigned long   *nitems_return, *bytes_after_return;
  206.         unsigned char** prop_return;
  207. } Xlib_GetWinProperty;
  208.  
  209. typedef struct {
  210.         Display*        display;
  211.         Window          w, p;
  212.         int             x, y;
  213. } Xlib_ReparentWindow;
  214.  
  215. typedef struct _xeventqueue {
  216.         XEvent event;
  217.         long qserial_num;
  218.         struct _xeventqueue *next;
  219. } Xlib_EventQueue;
  220.  
  221. typedef struct {
  222.         int pixels, points;
  223.         int avgwidth;
  224.         int hres, vres;
  225. } Xlib_FontHints;
  226.  
  227. #include "X11pmhk.h"
  228.  
  229. #define PMXLIB_DEFAULT_ICON     0x2000
  230.  
  231. HAB mainhab;
  232. HMQ mainhmq;
  233. HWND mainhwnd; /* Object instance window handle */
  234. HWND hwndDesktop;
  235. HATOMTBL pmatomtbl;
  236. pthread_t pmthread, mainthread;
  237. Display *maindisplay;
  238. int xinitialized, auto_repeat;
  239.  
  240. Xlib_EventQueue *EventQueue;
  241. /*Xlib_Grab *Grab;*/
  242. Xlib_Grab *(*Xlib_NewGrab)(void);
  243. void (*Xlib_RemoveGrab)(int);
  244. void (*Xlib_RemoveGrabAny)(int);
  245. Xlib_Grab *(*Xlib_FindGrab)(int);
  246. PFN Xlib_InputQueueHook;
  247.  
  248. int pmout[2];
  249.  
  250. pthread_mutex_t evmutex;
  251.  
  252. int wndcount, UM_FLUSH;
  253. Xlib_GC *gctouched;
  254.  
  255. char** atomNames;
  256. Atom* atomValues;
  257.  
  258. USHORT GXtoMixMode[16];
  259. USHORT LineStyletoLineType[3];
  260. USHORT CapStyletoLineEnd[4];
  261. USHORT JoinStyletoLineJoin[3];
  262.  
  263. GC GCList[1025];
  264.  
  265. int RestoreGCValues(HPS, XGCValues *, XGCValues *);
  266. XWindowAttributes *GetWinAttrib(Drawable, HPS *);
  267. int GetDrawableHeight(Drawable, GC, HPS *, int);
  268.  
  269. int RenderFontName(FONTMETRICS *, char *, Xlib_FontHints *, Xlib_Font *);
  270. int PatternMatch(char *, int, char *, int);
  271. int FontFileCountDashes(char *, int);
  272. FONTMETRICS *Xlib_LoadFont(char *, Xlib_Font *);
  273. XFontProp *Xlib_NewFontProp(HPS, FONTMETRICS *, int *n_properties);
  274. XCharStruct *Xlib_NewCharBounds(HPS, FONTMETRICS *, XCharStruct *min, XCharStruct *max);
  275.  
  276. #ifdef OS2I18N
  277. void Xlib_InitOS2I18N(void);
  278. int Xlib_XlatUCS_2(char *tgt, int tgt_size, void *src, int src_size);
  279. int Xlib_XlatISO8859_1(char *tgt, int tgt_size, char *src, int src_size);
  280. #endif
  281.  
  282. LONG Xlib_AllocFontAtom(Xlib_Pixmap *client, Xlib_Font *font);
  283. LONG Xlib_AllocPixmapAtom(Xlib_Pixmap *client, Xlib_Pixmap *pixmap);
  284. void Xlib_FreePMAtom(Xlib_Pixmap *client, LONG atom);
  285. void Xlib_FreeAllAtoms(Xlib_Pixmap *client);
  286. void Xlib_FreeFontAtom(Xlib_Font *font);
  287. void Xlib_FreePixmapAtom(Xlib_Pixmap *pixmap);
  288. void Xlib_MonitorResource(XID *resource);
  289. void Xlib_UnmonitorResource(XID *resource);
  290. void Xlib_InvalidateResource(XID resource);
  291.  
  292. void Xlib_SetGC(HPS hps, Xlib_GC *xgc);
  293.  
  294. XExtData *new_xextdata(void);
  295. int free_xextdata(XExtData *);
  296.  
  297. Screen *new_screen(Display *);
  298. int free_screen(Screen *);
  299.  
  300. Visual *new_visual(void);
  301. int free_visual(Visual *);
  302.  
  303. XEvent *Xlib_NewEvent(void);
  304. void Xlib_RemoveEvent(XEvent *ev);
  305.  
  306. Status Xlib_SendEvent(Display *display, Window w, Bool propagate,
  307.                   long event_mask, XEvent *event_send, Bool send_event);
  308.  
  309. /*BOOL EXPENTRY InputQueueHook (HAB hab, PQMSG pQmsg, USHORT fs);*/
  310.  
  311. void Xlib_crash(int signal);
  312.  
  313. int _XFreeExtData (XExtData*);
  314.  
  315. char *__XOS2RedirRoot(char *fname);
  316. int _XGetHostname(char* buf, int maxlen);
  317. void Xlib_GetDrawableInfo(Drawable d, GC gc, HPS *hps, int pathtype, long *width, long *height);
  318.  
  319. extern int _XTextHeight(
  320. #if NeedFunctionPrototypes
  321.     XFontStruct*        /* font_struct */,
  322.     _Xconst char*       /* string */,
  323.     int                 /* count */
  324. #endif
  325. );
  326.  
  327. extern int _XTextHeight16(
  328. #if NeedFunctionPrototypes
  329.     XFontStruct*        /* font_struct */,
  330.     _Xconst XChar2b*    /* string */,
  331.     int                 /* count */
  332. #endif
  333. );
  334.  
  335. void * pm_thread(void * arg);
  336.  
  337. #define x11_console_notice(info) fprintf(stdout,"%s\n",info)
  338. #define Xmalloc(size) malloc(size)
  339. #define Xcalloc(a,size) calloc((a),(size))
  340. #define Xfree(ptr) free(ptr)
  341. #define Xrealloc(ptr,size) realloc((ptr),(size))
  342.  
  343. XrmQuark _XrmInternalStringToQuark(register _Xconst char *name, register int len,
  344.         register unsigned long sig, Bool permstring);
  345.  
  346. #define min(a,b) (((a) < (b)) ? (a) : (b))
  347. #define max(a,b) (((a) > (b)) ? (a) : (b))
  348.  
  349. #ifdef XTHREADS
  350. #define LockDisplay(display) pthread_mutex_lock(&_Xglobal_lock)
  351. #define UnlockDisplay(display) pthread_mutex_unlock(&_Xglobal_lock)
  352. #define _XUnlockMutex(mutex) pthread_mutex_unlock(&((pthread_mutex_t)mutex))
  353. #define _XLockMutex(mutex) pthread_mutex_lock(&((pthread_mutex_t)mutex))
  354. #define _XCreateMutex(mutex) _pthread_mutex_init(&((pthread_mutex_t)mutex), NULL)
  355. #define _XFreeMutex(mutes) _pthread_mutex_destroy(&((pthread_mutex_t)mutex))
  356. #else
  357. #define LockDisplay(display)
  358. #define UnlockDisplay(display)
  359. #define _XUnlockMutex(mutex)
  360. #define _XLockMutex(mutex)
  361. #define _XCreateMutex(mutex)
  362. #define _XFreeMutex(mutes)
  363. #endif
  364.  
  365. #define CI_NONEXISTCHAR(cs) (((cs)->width == 0) && \
  366.                              (((cs)->rbearing|(cs)->lbearing| \
  367.                                (cs)->ascent|(cs)->descent) == 0))
  368.  
  369. /*
  370.  * CI_GET_CHAR_INFO_1D - return the charinfo struct for the indicated 8bit
  371.  * character.  If the character is in the column and exists, then return the
  372.  * appropriate metrics (note that fonts with common per-character metrics will
  373.  * return min_bounds).  If none of these hold true, try again with the default
  374.  * char.
  375.  */
  376. #define CI_GET_CHAR_INFO_1D(fs,col,def,cs) \
  377. { \
  378.     cs = def; \
  379.     if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
  380.         if (fs->per_char == NULL) { \
  381.             cs = &fs->min_bounds; \
  382.         } else { \
  383.             cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \
  384.             if (CI_NONEXISTCHAR(cs)) cs = def; \
  385.         } \
  386.     } \
  387. }
  388.  
  389. #define CI_GET_DEFAULT_INFO_1D(fs,cs) \
  390.   CI_GET_CHAR_INFO_1D (fs, fs->default_char, NULL, cs)
  391.  
  392.  
  393.  
  394. /*
  395.  * CI_GET_CHAR_INFO_2D - return the charinfo struct for the indicated row and
  396.  * column.  This is used for fonts that have more than row zero.
  397.  */
  398. #define CI_GET_CHAR_INFO_2D(fs,row,col,def,cs) \
  399. { \
  400.     cs = def; \
  401.     if (row >= fs->min_byte1 && row <= fs->max_byte1 && \
  402.         col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
  403.         if (fs->per_char == NULL) { \
  404.             cs = &fs->min_bounds; \
  405.         } else { \
  406.             cs = &fs->per_char[((row - fs->min_byte1) * \
  407.                                 (fs->max_char_or_byte2 - \
  408.                                  fs->min_char_or_byte2 + 1)) + \
  409.                                (col - fs->min_char_or_byte2)]; \
  410.             if (CI_NONEXISTCHAR(cs)) cs = def; \
  411.         } \
  412.     } \
  413. }
  414.  
  415. #define CI_GET_DEFAULT_INFO_2D(fs,cs) \
  416. { \
  417.     unsigned int r = (fs->default_char >> 8); \
  418.     unsigned int c = (fs->default_char & 0xff); \
  419.     CI_GET_CHAR_INFO_2D (fs, r, c, NULL, cs); \
  420. }
  421.  
  422. extern char *_XAllocScratch(
  423. #if NeedFunctionPrototypes
  424.     Display*            /* dpy */,
  425.     unsigned long       /* nbytes */
  426. #endif
  427. );
  428. extern char *_XAllocTemp(
  429. #if NeedFunctionPrototypes
  430.     Display*            /* dpy */,
  431.     unsigned long       /* nbytes */
  432. #endif
  433. );
  434. extern void _XFreeTemp(
  435. #if NeedFunctionPrototypes
  436.     Display*            /* dpy */,
  437.     char*               /* buf */,
  438.     unsigned long       /* nbytes */
  439. #endif
  440. );
  441.  
  442. #define SyncHandle() \
  443.         if (dpy->synchandler) (*dpy->synchandler)(dpy)
  444.  
  445. extern int _XError(
  446. #if NeedFunctionPrototypes
  447.     Display*    /* dpy */,
  448.     xError*     /* rep */
  449. #endif
  450. );
  451. extern int _XIOError(
  452. #if NeedFunctionPrototypes
  453.     Display*    /* dpy */
  454. #endif
  455. );
  456. extern int (*_XIOErrorFunction)(
  457. #if NeedNestedPrototypes
  458.     Display*    /* dpy */
  459. #endif
  460. );
  461. extern int (*_XErrorFunction)(
  462. #if NeedNestedPrototypes
  463.     Display*            /* dpy */,
  464.     XErrorEvent*        /* error_event */
  465. #endif
  466. );
  467.  
  468. /* internal connections for IMs */
  469.  
  470. typedef void (*_XInternalConnectionProc)(
  471. #if NeedFunctionPrototypes
  472.     Display*                    /* dpy */,
  473.     int                         /* fd */,
  474.     XPointer                    /* call_data */
  475. #endif
  476. );
  477.  
  478.  
  479. extern Status _XRegisterInternalConnection(
  480. #if NeedFunctionPrototypes
  481.     Display*                    /* dpy */,
  482.     int                         /* fd */,
  483.     _XInternalConnectionProc    /* callback */,
  484.     XPointer                    /* call_data */
  485. #endif
  486. );
  487.  
  488. extern void _XUnregisterInternalConnection(
  489. #if NeedFunctionPrototypes
  490.     Display*                    /* dpy */,
  491.     int                         /* fd */
  492. #endif
  493. );
  494.  
  495. /* Display structure has pointers to these */
  496.  
  497. struct _XConnectionInfo {       /* info from _XRegisterInternalConnection */
  498.     int fd;
  499.     _XInternalConnectionProc read_callback;
  500.     XPointer call_data;
  501.     XPointer *watch_data;       /* set/used by XConnectionWatchProc */
  502.     struct _XConnectionInfo *next;
  503. };
  504.  
  505. struct _XConnWatchInfo {        /* info from XAddConnectionWatch */
  506.     XConnectionWatchProc fn;
  507.     XPointer client_data;
  508.     struct _XConnWatchInfo *next;
  509. };
  510.  
  511. #ifdef DEBUG
  512.  
  513. volatile struct Xlib_DebugInfo_st {
  514.         char    *filename;
  515.         int     linenumb;
  516.         char    *procname,*procinfo;
  517. } Xlib_DebugInfo[1024];
  518. volatile int Xlib_DebugOffset;
  519.  
  520. int Xlib_DebugEnter(char*,int,char*,char*);
  521.  
  522. #define DBUG_ENTER(a)                                           \
  523.         int DebugLevel = Xlib_DebugEnter(__FILE__,__LINE__,(a),"");
  524. #define DBUG_POINT(a) {                                         \
  525.                 Xlib_DebugInfo[DebugLevel].linenumb = __LINE__; \
  526.                 Xlib_DebugInfo[DebugLevel].procinfo = a;        \
  527.         }
  528. #define DBUG_LEAVE {                                            \
  529.                 Xlib_DebugInfo[DebugLevel].linenumb = __LINE__; \
  530.                 Xlib_DebugOffset = --DebugLevel;                \
  531.         }
  532. #define DBUG_RETURN(a) {                                        \
  533.                 DBUG_LEAVE;                                     \
  534.                 return (a);                                     \
  535.         }
  536. #define DBUG_VOID_RETURN {                                      \
  537.                 DBUG_LEAVE;                                     \
  538.                 return;                                         \
  539.         }
  540. #else
  541. #define DBUG_ENTER(a)
  542. #define DBUG_POINT(a)
  543. #define DBUG_RETURN(a) return (a)
  544. #define DBUG_VOID_RETURN return
  545. #endif
  546.  
  547.  
  548. #endif
  549.