home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1999 March / PCShareware-3-99.iso / IMPLE / DJGPP.RAR / DJGPP2 / XLIB-SR0.ZIP / SRC / EXTENSIO / EXTUTIL.H < prev    next >
C/C++ Source or Header  |  1989-12-09  |  4KB  |  124 lines

  1. /*
  2.  * $XConsortium: extutil.h,v 1.11 89/12/09 21:12:33 rws Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Jim Fulton, MIT X Consortium
  24.  * 
  25.  *                     Xlib Extension-Writing Utilities
  26.  *
  27.  * This package contains utilities for writing the client API for various
  28.  * protocol extensions.  THESE INTERFACES ARE NOT PART OF THE X STANDARD AND
  29.  * ARE SUBJECT TO CHANGE!
  30.  */
  31.  
  32. #ifndef _EXTUTIL_H_
  33. #define _EXTUTIL_H_
  34.  
  35. /*
  36.  * We need to keep a list of open displays since the Xlib display list isn't
  37.  * public.  We also have to per-display info in a separate block since it isn't
  38.  * stored directly in the Display structure.
  39.  */
  40. typedef struct _XExtDisplayInfo {
  41.     struct _XExtDisplayInfo *next;    /* keep a linked list */
  42.     Display *display;            /* which display this is */
  43.     XExtCodes *codes;            /* the extension protocol codes */
  44.     caddr_t data;            /* extra data for extension to use */
  45. } XExtDisplayInfo;
  46.  
  47. typedef struct _XExtensionInfo {
  48.     XExtDisplayInfo *head;        /* start of list */
  49.     XExtDisplayInfo *cur;        /* most recently used */
  50.     int ndisplays;            /* number of displays */
  51. } XExtensionInfo;
  52.  
  53. typedef struct _XExtensionHooks {
  54.     int (*create_gc)();
  55.     int (*copy_gc)();
  56.     int (*flush_gc)();
  57.     int (*free_gc)();
  58.     int (*create_font)();
  59.     int (*free_font)();
  60.     int (*close_display)();
  61.     Bool (*wire_to_event)();
  62.     Status (*event_to_wire)();
  63.     int (*error)();
  64.     char *(*error_string)();
  65. } XExtensionHooks;
  66.  
  67. extern XExtensionInfo *XextCreateExtension();
  68. extern void XextDestroyExtension();
  69. extern XExtDisplayInfo *XextAddDisplay();
  70. extern int XextRemoveDisplay();
  71. extern XExtDisplayInfo *XextFindDisplay();
  72.  
  73. #define XextHasExtension(i) ((i) && ((i)->codes))
  74. #define XextCheckExtension(dpy,i,name,val) \
  75.   if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return val; }
  76. #define XextSimpleCheckExtension(dpy,i,name) \
  77.   if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return; }
  78.  
  79.  
  80. /*
  81.  * helper macros to generate code that is common to all extensions; caller
  82.  * should prefix it with static if extension source is in one file; this
  83.  * could be a utility function, but have to stack 6 unused arguments for 
  84.  * something that is called many, many times would be bad.
  85.  */
  86. #define XEXT_GENERATE_FIND_DISPLAY(proc,extinfo,extname,hooks,nev,data) \
  87. XExtDisplayInfo *proc (dpy) \
  88.     register Display *dpy; \
  89. { \
  90.     XExtDisplayInfo *dpyinfo; \
  91.     if (!extinfo) { if (!(extinfo = XextCreateExtension())) return NULL; } \
  92.     if (!(dpyinfo = XextFindDisplay (extinfo, dpy))) \
  93.       dpyinfo = XextAddDisplay (extinfo,dpy,extname,hooks,nev,data); \
  94.     return dpyinfo; \
  95. }
  96.  
  97. #define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \
  98. int proc (dpy, codes) \
  99.     Display *dpy; \
  100.     XExtCodes *codes; \
  101. { \
  102.     return XextRemoveDisplay (extinfo, dpy); \
  103. }
  104.  
  105. #define XEXT_GENERATE_ERROR_STRING(proc,extname,nerr,errl) \
  106. char *proc (dpy, code, codes, buf, n) \
  107.     Display  *dpy; \
  108.     int code; \
  109.     XExtCodes *codes; \
  110.     char *buf; \
  111.     int n; \
  112. {  \
  113.     code -= codes->first_error;  \
  114.     if (code >= 0 && code < nerr) { \
  115.     char tmp[256]; \
  116.     sprintf (tmp, "%s.%d", extname, code); \
  117.     XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \
  118.     return buf; \
  119.     } \
  120.     return (char *)0; \
  121. }
  122.  
  123. #endif
  124.