home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xtrapv33.zip / extensions / lib / xtrap / XECallBcks.c < prev    next >
C/C++ Source or Header  |  1992-09-14  |  6KB  |  246 lines

  1. /*****************************************************************************
  2. Copyright 1987, 1988, 1989, 1990, 1991 by Digital Equipment Corp., Maynard, MA
  3.  
  4. Permission to use, copy, modify, and distribute this software and its 
  5. documentation for any purpose and without fee is hereby granted, 
  6. provided that the above copyright notice appear in all copies and that
  7. both that copyright notice and this permission notice appear in 
  8. supporting documentation, and that the name of Digital not be
  9. used in advertising or publicity pertaining to distribution of the
  10. software without specific, written prior permission.  
  11.  
  12. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  13. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  14. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  15. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  16. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  17. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  18. SOFTWARE.
  19.  
  20. *****************************************************************************/
  21. /*
  22.  *
  23.  *  CONTRIBUTORS:
  24.  *
  25.  *      Dick Annicchiarico
  26.  *      Robert Chesler
  27.  *      Dan Coutu
  28.  *      Gene Durso
  29.  *      Marc Evans
  30.  *      Alan Jamison
  31.  *      Mark Henry
  32.  *      Ken Miller
  33.  *
  34.  */
  35. /*
  36.  * This file contains XETrap Callback initilization routines.
  37.  * The callback data hang off of the TC and are freed as part of the
  38.  * XEFreeTC routine.
  39.  */
  40.  
  41. #include "Xos.h"
  42. #include "xtraplib.h"
  43. #include "xtraplibp.h"
  44.  
  45. #ifndef lint
  46. static char SCCSID[] = "@(#)XECallbacks.c    1.10 - 90/09/18  ";
  47. static char RCSID[] = "$Header$";
  48. #endif
  49.  
  50. #ifdef FUNCTION_PROTOS
  51. int XEAddRequestCB(XETC *tc, CARD8 req, void_function func, BYTE *data)
  52. #else
  53. int XEAddRequestCB(tc, req, func, data)
  54.     XETC          *tc;
  55.     CARD8         req;
  56.     void_function func;
  57.     BYTE          *data;
  58. #endif
  59. {
  60.     if (!tc->values.req_cb)
  61.     {   /* This is the first time for this particular TC, need to malloc */
  62.         if ((tc->values.req_cb =
  63.             (XETrapCB *)XtCalloc(256L,sizeof(XETrapCB))) == NULL)
  64.         {
  65.             /* XtCalloc already reported the error */
  66.             return(False);
  67.         }
  68.     }
  69.     tc->values.req_cb[req].func = func;
  70.     tc->values.req_cb[req].data = data;
  71.  
  72.     return(True);
  73. }
  74.  
  75. #ifdef FUNCTION_PROTOS
  76. int XEAddRequestCBs(XETC *tc, ReqFlags req_flags, void_function func,
  77.     BYTE *data)
  78. #else
  79. int XEAddRequestCBs(tc, req_flags, func, data)
  80.     XETC          *tc;
  81.     ReqFlags      req_flags;
  82.     void_function func;
  83.     BYTE          *data;
  84. #endif
  85. {
  86.     int i;
  87.     int status = True;
  88.  
  89.     for (i=0; i<=255L; i++)
  90.     {
  91.         if (BitIsTrue(req_flags, i))
  92.         {
  93.             status = XEAddRequestCB(tc, (CARD8)i, func, data);
  94.         }
  95.     }
  96.     return(status);
  97. }
  98.  
  99. #ifdef FUNCTION_PROTOS
  100. int XEAddEventCB(XETC *tc, CARD8 evt, void_function func, BYTE *data)
  101. #else
  102. int XEAddEventCB(tc, evt, func, data)
  103.     XETC          *tc;
  104.     CARD8         evt;
  105.     void_function func;
  106.     BYTE          *data;
  107. #endif
  108. {
  109.     if (!tc->values.evt_cb)
  110.     {   /* This is the first time for this particular TC, need to malloc */
  111.         if ((tc->values.evt_cb = 
  112.             (XETrapCB *)XtCalloc(XETrapCoreEvents,sizeof(XETrapCB))) == NULL)
  113.         {
  114.             /* XtCalloc already reported the error */
  115.             return(False);
  116.         }
  117.     }
  118.     tc->values.evt_cb[evt].func = func;
  119.     tc->values.evt_cb[evt].data = data;
  120.  
  121.     return(True);
  122. }
  123.  
  124. #ifdef FUNCTION_PROTOS
  125. int XEAddEventCBs(XETC *tc, EventFlags evt_flags, void_function func,
  126.     BYTE *data)
  127. #else
  128. int XEAddEventCBs(tc, evt_flags, func, data)
  129.     XETC          *tc;
  130.     EventFlags    evt_flags;
  131.     void_function func;
  132.     BYTE          *data;
  133. #endif
  134. {
  135.     int i;
  136.     int status = True;
  137.  
  138.     for (i=KeyPress; i<=MotionNotify; i++)
  139.     {
  140.         if (BitIsTrue(evt_flags, i))
  141.         {
  142.             status = XEAddEventCB(tc, (CARD8)i, func, data);
  143.         }
  144.     }
  145.     return(status);
  146. }
  147.  
  148. #ifdef FUNCTION_PROTOS
  149. void XERemoveRequestCB(XETC *tc, CARD8 req)
  150. #else
  151. void XERemoveRequestCB(tc, req)
  152.     XETC         *tc;
  153.     CARD8        req;
  154. #endif
  155. {
  156.     if (!tc->values.req_cb)
  157.     {   /* We gotta problem!  CB struct not allocated! */
  158.         return;
  159.     }
  160.     tc->values.req_cb[req].func = (void_function)NULL;
  161.     tc->values.req_cb[req].data = (BYTE *)NULL;
  162.     return;
  163. }
  164. #ifdef FUNCTION_PROTOS
  165. void XERemoveRequestCBs(XETC *tc, ReqFlags req_flags)
  166. #else
  167. void XERemoveRequestCBs(tc, req_flags)
  168.     XETC         *tc;
  169.     ReqFlags     req_flags;
  170. #endif
  171. {
  172.     int i;
  173.  
  174.     for (i=0; i<=255L; i++)
  175.     {
  176.         if (BitIsTrue(req_flags, i))
  177.         {
  178.             XERemoveRequestCB(tc, (CARD8)i);
  179.         }
  180.     }
  181. }
  182.  
  183. #ifdef FUNCTION_PROTOS
  184. void XERemoveAllRequestCBs(XETC *tc)
  185. #else
  186. void XERemoveAllRequestCBs(tc)
  187.     XETC         *tc;
  188. #endif
  189. {
  190.     if (!tc->values.req_cb)
  191.     {   /* We gotta problem!  CB struct not allocated! */
  192.         return;
  193.     }
  194.     XtFree(tc->values.req_cb);
  195. }
  196.  
  197. #ifdef FUNCTION_PROTOS
  198. void XERemoveEventCB(XETC *tc, CARD8 evt)
  199. #else
  200. void XERemoveEventCB(tc, evt)
  201.     XETC         *tc;
  202.     CARD8        evt;
  203. #endif
  204. {
  205.     if (!tc->values.evt_cb)
  206.     {   /* We gotta problem!  CB struct not allocated! */
  207.         return;
  208.     }
  209.     tc->values.evt_cb[evt].func = (void_function)NULL;
  210.     tc->values.evt_cb[evt].data = (BYTE *)NULL;
  211.     return;
  212. }
  213.  
  214. #ifdef FUNCTION_PROTOS
  215. void XERemoveEventCBs(XETC *tc, EventFlags evt_flags)
  216. #else
  217. void XERemoveEventCBs(tc, evt_flags)
  218.     XETC         *tc;
  219.     EventFlags   evt_flags;
  220. #endif
  221. {
  222.     int i;
  223.  
  224.     for (i=KeyPress; i<=MotionNotify; i++)
  225.     {
  226.         if (BitIsTrue(evt_flags, i))
  227.         {
  228.             XERemoveEventCB(tc, (CARD8)i);
  229.         }
  230.     }
  231. }
  232.  
  233. #ifdef FUNCTION_PROTOS
  234. void XERemoveAllEventCBs(XETC *tc)
  235. #else
  236. void XERemoveAllEventCBs(tc)
  237.     XETC         *tc;
  238. #endif
  239. {
  240.     if (!tc->values.evt_cb)
  241.     {   /* We gotta problem!  CB struct not allocated! */
  242.         return;
  243.     }
  244.     XtFree(tc->values.evt_cb);
  245. }
  246.