home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xlib_InitExt.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  14KB  |  497 lines

  1. /* $XConsortium: InitExt.c /main/22 1996/10/22 14:19:47 kaleb $ */
  2. /*
  3.  
  4. Copyright (c) 1987  X Consortium
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining
  7. a copy of this software and associated documentation files (the
  8. "Software"), to deal in the Software without restriction, including
  9. without limitation the rights to use, copy, modify, merge, publish,
  10. distribute, sublicense, and/or sell copies of the Software, and to
  11. permit persons to whom the Software is furnished to do so, subject to
  12. the following conditions:
  13.  
  14. The above copyright notice and this permission notice shall be included
  15. in all copies or substantial portions of the Software.
  16.  
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. OTHER DEALINGS IN THE SOFTWARE.
  24.  
  25. Except as contained in this notice, the name of the X Consortium shall
  26. not be used in advertising or otherwise to promote the sale, use or
  27. other dealings in this Software without prior written authorization
  28. from the X Consortium.
  29.  
  30. */
  31.  
  32. #include "Xlib_private.h"
  33. #include <X11/Xos.h>
  34. #include <stdio.h>
  35.  
  36. extern Bool _XUnknownWireEvent();
  37. extern Status _XUnknownNativeEvent();
  38. extern Bool _XDefaultWireError();
  39.  
  40. /*
  41.  * This routine is used to link a extension in so it will be called
  42.  * at appropriate times.
  43.  */
  44.  
  45. #if NeedFunctionPrototypes
  46. XExtCodes *XInitExtension (
  47.     Display *dpy,
  48.     _Xconst char *name)
  49. #else
  50. XExtCodes *XInitExtension (dpy, name)
  51.     Display *dpy;
  52.     char *name;
  53. #endif
  54. {
  55.     DBUG_ENTER("XInitExtension")
  56.     XExtCodes codes;    /* temp. place for extension information. */
  57.     register _XExtension *ext;/* need a place to build it all */
  58.     if (!XQueryExtension(dpy, name, 
  59.         &codes.major_opcode, &codes.first_event,
  60.         &codes.first_error)) DBUG_RETURN(NULL);
  61.  
  62.     LockDisplay (dpy);
  63.     if (! (ext = (_XExtension *) Xcalloc (1, sizeof (_XExtension))) ||
  64.         ! (ext->name = Xmalloc((unsigned) strlen(name) + 1))) {
  65.         if (ext) Xfree((char *) ext);
  66.         UnlockDisplay(dpy);
  67.         DBUG_RETURN((XExtCodes *) NULL);
  68.     }
  69.     codes.extension = dpy->ext_number++;
  70.     ext->codes = codes;
  71.     (void) strcpy(ext->name, name);
  72.  
  73.     /* chain it onto the display list */    
  74.     ext->next = dpy->ext_procs;
  75.     dpy->ext_procs = ext;
  76.     UnlockDisplay (dpy);
  77.  
  78.     DBUG_RETURN(&ext->codes);        /* tell him which extension */
  79. }
  80.  
  81. XExtCodes *XAddExtension (dpy)
  82.     Display *dpy;
  83. {
  84.     DBUG_ENTER("XAddExtension")
  85.     register _XExtension *ext;
  86.  
  87.     LockDisplay (dpy);
  88.     if (! (ext = (_XExtension *) Xcalloc (1, sizeof (_XExtension)))) {
  89.     UnlockDisplay(dpy);
  90.     DBUG_RETURN((XExtCodes *) NULL);
  91.     }
  92.     ext->codes.extension = dpy->ext_number++;
  93.  
  94.     /* chain it onto the display list */
  95.     ext->next = dpy->ext_procs;
  96.     dpy->ext_procs = ext;
  97.     UnlockDisplay (dpy);
  98.  
  99.     DBUG_RETURN(&ext->codes);        /* tell him which extension */
  100. }
  101.  
  102. static _XExtension *XLookupExtension (dpy, extension)
  103.     register Display *dpy;    /* display */
  104.     register int extension;    /* extension number */
  105. {
  106.     DBUG_ENTER("XLookupExtension")
  107.     register _XExtension *ext;
  108.     for (ext = dpy->ext_procs; ext; ext = ext->next)
  109.         if (ext->codes.extension == extension) DBUG_RETURN(ext);
  110.     DBUG_RETURN(NULL);
  111. }
  112.  
  113. XExtData **XEHeadOfExtensionList(object)
  114.     XEDataObject object;
  115. {
  116.     DBUG_ENTER("XEHeadOfExtensionList")
  117.     XExtData **result = *(XExtData ***)&object;
  118.     DBUG_RETURN(result);
  119. }
  120.  
  121. int XAddToExtensionList(structure, ext_data)
  122.     XExtData **structure;
  123.     XExtData *ext_data;
  124. {
  125.     DBUG_ENTER("XAddToExtensionList")
  126.     ext_data->next = *structure;
  127.     *structure = ext_data;
  128.     DBUG_RETURN(1);
  129. }
  130.  
  131. XExtData *XFindOnExtensionList(structure, number)
  132.     XExtData **structure;
  133.     int number;
  134. {
  135.     DBUG_ENTER("XFindOnExtensionList")
  136.     XExtData *ext;
  137.  
  138.     ext = *structure;
  139.     while (ext && (ext->number != number))
  140.     ext = ext->next;
  141.     DBUG_RETURN(ext);
  142. }
  143.  
  144. typedef int (*CreateGCType) (
  145. #if NeedFunctionPrototypes
  146.     Display*    /* display */,
  147.     GC        /* gc */,
  148.     XExtCodes*    /* codes */
  149. #endif
  150. );
  151.  
  152. /*
  153.  * Routines to hang procs on the extension structure.
  154.  */
  155. CreateGCType XESetCreateGC(dpy, extension, proc)
  156.     Display *dpy;        /* display */
  157.     int extension;        /* extension number */
  158.     CreateGCType proc;    /* routine to call when GC created */
  159. {
  160.     DBUG_ENTER("XESetCreateGC")
  161.     register _XExtension *e;    /* for lookup of extension */
  162.     register int (*oldproc)();
  163.     if ((e = XLookupExtension (dpy, extension)) == NULL) DBUG_RETURN(NULL);
  164.     LockDisplay(dpy);
  165.     oldproc = e->create_GC;
  166.     e->create_GC = proc;
  167.     UnlockDisplay(dpy);
  168.     DBUG_RETURN((CreateGCType)oldproc);
  169. }
  170.  
  171. typedef int (*CopyGCType)(
  172. #if NeedFunctionPrototypes
  173.     Display*    /* display */,
  174.     GC        /* gc */,
  175.     XExtCodes*    /* codes */
  176. #endif
  177. );
  178.  
  179. CopyGCType XESetCopyGC(dpy, extension, proc)
  180.     Display *dpy;        /* display */
  181.     int extension;        /* extension number */
  182.     CopyGCType proc;    /* routine to call when GC copied */
  183. {
  184.     DBUG_ENTER("XESetCopyGC")
  185.     register _XExtension *e;    /* for lookup of extension */
  186.     register int (*oldproc)();
  187.     if ((e = XLookupExtension (dpy, extension)) == NULL) DBUG_RETURN(NULL);
  188.     LockDisplay(dpy);
  189.     oldproc = e->copy_GC;
  190.     e->copy_GC = proc;
  191.     UnlockDisplay(dpy);
  192.     DBUG_RETURN((CopyGCType)oldproc);
  193. }
  194.  
  195. typedef int (*FlushGCType) (
  196. #if NeedFunctionPrototypes
  197.     Display*    /* display */,
  198.     GC        /* gc */,
  199.     XExtCodes*    /* codes */
  200. #endif
  201. );
  202.  
  203. FlushGCType XESetFlushGC(dpy, extension, proc)
  204.     Display *dpy;        /* display */
  205.     int extension;        /* extension number */
  206.     FlushGCType proc;    /* routine to call when GC copied */
  207. {
  208.     DBUG_ENTER("XESetFlushGC")
  209.     register _XExtension *e;    /* for lookup of extension */
  210.     register int (*oldproc)();
  211.     if ((e = XLookupExtension (dpy, extension)) == NULL) DBUG_RETURN(NULL);
  212.     LockDisplay(dpy);
  213.     oldproc = e->flush_GC;
  214.     e->flush_GC = proc;
  215.     UnlockDisplay(dpy);
  216.     DBUG_RETURN((FlushGCType)oldproc);
  217. }
  218.  
  219. typedef int (*FreeGCType) (
  220. #if NeedFunctionPrototypes
  221.     Display*    /* display */,
  222.     GC        /* gc */,
  223.     XExtCodes*    /* codes */
  224. #endif
  225. );
  226.  
  227. FreeGCType XESetFreeGC(dpy, extension, proc)
  228.     Display *dpy;        /* display */
  229.     int extension;        /* extension number */
  230.     FreeGCType proc;    /* routine to call when GC freed */
  231. {
  232.     DBUG_ENTER("XESetFreeGC")
  233.     register _XExtension *e;    /* for lookup of extension */
  234.     register int (*oldproc)();
  235.     if ((e = XLookupExtension (dpy, extension)) == NULL) DBUG_RETURN(NULL);
  236.     LockDisplay(dpy);
  237.     oldproc = e->free_GC;
  238.     e->free_GC = proc;
  239.     UnlockDisplay(dpy);
  240.     DBUG_RETURN((FreeGCType)oldproc);
  241. }
  242.  
  243. typedef int (*CreateFontType) (
  244. #if NeedFunctionPrototypes
  245.     Display*    /* display */,
  246.     XFontStruct* /* fs */,
  247.     XExtCodes*    /* codes */
  248. #endif
  249. );
  250.  
  251. CreateFontType XESetCreateFont(dpy, extension, proc)
  252.     Display *dpy;        /* display */
  253.     int extension;        /* extension number */
  254.     CreateFontType proc;    /* routine to call when font created */
  255. {
  256.     DBUG_ENTER("XESetCreateFont")
  257.     register _XExtension *e;    /* for lookup of extension */
  258.     register int (*oldproc)();
  259.     if ((e = XLookupExtension (dpy, extension)) == NULL) DBUG_RETURN(NULL);
  260.     LockDisplay(dpy);
  261.     oldproc = e->create_Font;
  262.     e->create_Font = proc;
  263.     UnlockDisplay(dpy);
  264.     DBUG_RETURN((CreateFontType)oldproc);
  265. }
  266.  
  267. typedef int (*FreeFontType) (
  268. #if NeedFunctionPrototypes
  269.     Display*    /* display */,
  270.     XFontStruct* /* fs */,
  271.     XExtCodes*    /* codes */
  272. #endif
  273. );
  274.  
  275. FreeFontType XESetFreeFont(dpy, extension, proc)
  276.     Display *dpy;        /* display */
  277.     int extension;        /* extension number */
  278.     FreeFontType proc;    /* routine to call when font freed */
  279. {
  280.     DBUG_ENTER("XESetFreeFont")
  281.     register _XExtension *e;    /* for lookup of extension */
  282.     register int (*oldproc)();
  283.     if ((e = XLookupExtension (dpy, extension)) == NULL) DBUG_RETURN(NULL);
  284.     LockDisplay(dpy);
  285.     oldproc = e->free_Font;
  286.     e->free_Font = proc;
  287.     UnlockDisplay(dpy);
  288.     DBUG_RETURN((FreeFontType)oldproc);
  289. }
  290.  
  291. typedef int (*CloseDisplayType) (
  292. #if NeedFunctionPrototypes
  293.     Display*    /* display */,
  294.     XExtCodes*    /* codes */
  295. #endif
  296. );
  297.  
  298. CloseDisplayType XESetCloseDisplay(dpy, extension, proc)
  299.     Display *dpy;        /* display */
  300.     int extension;        /* extension number */
  301.     CloseDisplayType proc;    /* routine to call when display closed */
  302. {
  303.     DBUG_ENTER("XESetCloseDisplay")
  304.     register _XExtension *e;    /* for lookup of extension */
  305.     register int (*oldproc)();
  306.     if ((e = XLookupExtension (dpy, extension)) == NULL) DBUG_RETURN(NULL);
  307.     LockDisplay(dpy);
  308.     oldproc = e->close_display;
  309.     e->close_display = proc;
  310.     UnlockDisplay(dpy);
  311.     DBUG_RETURN((CloseDisplayType)oldproc);
  312. }
  313.  
  314. typedef Bool (*WireToEventType) (
  315. #if NeedFunctionPrototypes
  316.     Display*    /* display */,
  317.     XEvent*    /* re */,
  318.     xEvent*    /* event */
  319. #endif
  320. );
  321.  
  322. WireToEventType XESetWireToEvent(dpy, event_number, proc)
  323.     Display *dpy;        /* display */
  324.     WireToEventType proc;    /* routine to call when converting event */
  325.     int event_number;    /* event routine to replace */
  326. {
  327.     DBUG_ENTER("XESetWireToEvent")
  328.     register Bool (*oldproc)();
  329.     if (proc == NULL) proc = (WireToEventType)_XUnknownWireEvent;
  330.     LockDisplay (dpy);
  331.     oldproc = dpy->event_vec[event_number];
  332.     dpy->event_vec[event_number] = proc;
  333.     UnlockDisplay (dpy);
  334.     DBUG_RETURN((WireToEventType)oldproc);
  335. }
  336.  
  337. typedef Status (*EventToWireType) (
  338. #if NeedFunctionPrototypes
  339.     Display*    /* display */,
  340.     XEvent*    /* re */,
  341.     xEvent*    /* event */
  342. #endif
  343. );
  344.  
  345. EventToWireType XESetEventToWire(dpy, event_number, proc)
  346.     Display *dpy;        /* display */
  347.     EventToWireType proc;    /* routine to call when converting event */
  348.     int event_number;    /* event routine to replace */
  349. {
  350.     DBUG_ENTER("XESetEventToWire")
  351.     register Status (*oldproc)();
  352.     if (proc == NULL) proc = (EventToWireType) _XUnknownNativeEvent;
  353.     LockDisplay (dpy);
  354.     oldproc = dpy->wire_vec[event_number];
  355.     dpy->wire_vec[event_number] = proc;
  356.     UnlockDisplay(dpy);
  357.     DBUG_RETURN((EventToWireType)oldproc);
  358. }
  359.  
  360. typedef Bool (*WireToErrorType) (
  361. #if NeedFunctionPrototypes
  362.     Display*    /* display */,
  363.     XErrorEvent* /* he */,
  364.     xError*    /* we */
  365. #endif
  366. );
  367.  
  368. WireToErrorType XESetWireToError(dpy, error_number, proc)
  369.     Display *dpy;        /* display */
  370.     WireToErrorType proc;    /* routine to call when converting error */
  371.     int error_number;    /* error routine to replace */
  372. {
  373.     DBUG_ENTER("XESetWireToError")
  374.     register Bool (*oldproc)() = NULL;
  375.     if (proc == NULL) proc = (WireToErrorType)_XDefaultWireError;
  376.     LockDisplay (dpy);
  377.     if (!dpy->error_vec) {
  378.         int i;
  379.         dpy->error_vec = (Bool (**)())Xmalloc(256 * sizeof(oldproc));
  380.         for (i = 1; i < 256; i++)
  381.         dpy->error_vec[i] = _XDefaultWireError;
  382.     }
  383.     if (dpy->error_vec) {
  384.         oldproc = dpy->error_vec[error_number];
  385.         dpy->error_vec[error_number] = proc;
  386.     }
  387.     UnlockDisplay (dpy);
  388.     DBUG_RETURN((WireToErrorType)oldproc);
  389. }
  390.  
  391. typedef int (*ErrorType) (
  392. #if NeedFunctionPrototypes
  393.     Display*    /* display */,
  394.     xError*    /* err */,
  395.     XExtCodes*    /* codes */,
  396.     int*    /* ret_code */
  397. #endif
  398. );
  399.  
  400. ErrorType XESetError(dpy, extension, proc)
  401.     Display *dpy;        /* display */
  402.     int extension;        /* extension number */
  403.     ErrorType proc;        /* routine to call when X error happens */
  404. {
  405.     DBUG_ENTER("XESetError")
  406.     register _XExtension *e;    /* for lookup of extension */
  407.     register int (*oldproc)();
  408.     if ((e = XLookupExtension (dpy, extension)) == NULL) DBUG_RETURN(NULL);
  409.     LockDisplay(dpy);
  410.     oldproc = e->error;
  411.     e->error = proc;
  412.     UnlockDisplay(dpy);
  413.     DBUG_RETURN((ErrorType)oldproc);
  414. }
  415.  
  416. typedef char* (*ErrorStringType) (
  417. #if NeedFunctionPrototypes
  418.     Display*    /* display */,
  419.     int        /* code */,
  420.     XExtCodes*    /* codes */,
  421.     char*    /* buffer */,
  422.     int        /* nbytes */
  423. #endif
  424. );
  425.  
  426. ErrorStringType XESetErrorString(dpy, extension, proc)
  427.     Display *dpy;        /* display */
  428.     int extension;        /* extension number */
  429.     ErrorStringType proc;    /* routine to call when I/O error happens */
  430. {
  431.     DBUG_ENTER("XESetErrorString")
  432.     register _XExtension *e;    /* for lookup of extension */
  433.     register char *(*oldproc)();
  434.     if ((e = XLookupExtension (dpy, extension)) == NULL) DBUG_RETURN(NULL);
  435.     LockDisplay(dpy);
  436.     oldproc = e->error_string;
  437.     e->error_string = proc;
  438.     UnlockDisplay(dpy);
  439.     DBUG_RETURN((ErrorStringType)oldproc);
  440. }
  441.  
  442. typedef void (*PrintErrorType)(
  443. #if NeedFunctionPrototypes
  444.     Display*    /* display */,
  445.     XErrorEvent* /* ev */,
  446.     void*    /* fp */
  447. #endif
  448. );
  449.  
  450. PrintErrorType XESetPrintErrorValues(dpy, extension, proc)
  451.     Display *dpy;        /* display */
  452.     int extension;        /* extension number */
  453.     PrintErrorType proc;    /* routine to call to print */
  454. {
  455.     DBUG_ENTER("XESetPrintErrorValues")
  456.     register _XExtension *e;    /* for lookup of extension */
  457.     register void (*oldproc)();
  458.     if ((e = XLookupExtension (dpy, extension)) == NULL) DBUG_RETURN(NULL);
  459.     LockDisplay(dpy);
  460.     oldproc = e->error_values;
  461.     e->error_values = proc;
  462.     UnlockDisplay(dpy);
  463.     DBUG_RETURN((PrintErrorType)oldproc);
  464. }
  465.  
  466. typedef void (*BeforeFlushType)(
  467. #if NeedFunctionPrototypes
  468.     Display*    /* display */,
  469.     XExtCodes*    /* codes */,
  470.     char*    /* data */,
  471.     long    /* len */
  472. #endif
  473. );
  474.  
  475. BeforeFlushType XESetBeforeFlush(dpy, extension, proc)
  476.     Display *dpy;        /* display */
  477.     int extension;        /* extension number */
  478.     BeforeFlushType proc;    /* routine to call on flush */
  479. {
  480.     DBUG_ENTER("XESetBeforeFlush")
  481.     register _XExtension *e;    /* for lookup of extension */
  482.     register void (*oldproc)();
  483.     register _XExtension *ext;
  484.     if ((e = XLookupExtension (dpy, extension)) == NULL) DBUG_RETURN(NULL);
  485.     LockDisplay(dpy);
  486.     oldproc = e->before_flush;
  487.     e->before_flush = proc;
  488.     for (ext = dpy->flushes; ext && ext != e; ext = ext->next)
  489.         ;
  490.     if (!ext) {
  491.         e->next_flush = dpy->flushes;
  492.         dpy->flushes = e;
  493.     }        
  494.     UnlockDisplay(dpy);
  495.     DBUG_RETURN((BeforeFlushType)oldproc);
  496. }
  497.