Tizen 2.0 Release
[pkgs/xorg/lib/libxtrap.git] / src / XECallBcks.c
1 /* $XFree86$ */
2 /*****************************************************************************
3 Copyright 1987, 1988, 1989, 1990, 1991 by Digital Equipment Corp., Maynard, MA
4
5 Permission to use, copy, modify, and distribute this software and its 
6 documentation for any purpose and without fee is hereby granted, 
7 provided that the above copyright notice appear in all copies and that
8 both that copyright notice and this permission notice appear in 
9 supporting documentation, and that the name of Digital not be
10 used in advertising or publicity pertaining to distribution of the
11 software without specific, written prior permission.  
12
13 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
14 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
15 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
16 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
18 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
19 SOFTWARE.
20
21 *****************************************************************************/
22 /*
23  *
24  *  CONTRIBUTORS:
25  *
26  *      Dick Annicchiarico
27  *      Robert Chesler
28  *      Dan Coutu
29  *      Gene Durso
30  *      Marc Evans
31  *      Alan Jamison
32  *      Mark Henry
33  *      Ken Miller
34  *
35  */
36 /*
37  * This file contains XETrap Callback initilization routines.
38  * The callback data hang off of the TC and are freed as part of the
39  * XEFreeTC routine.
40  */
41
42 #include <X11/Xos.h>
43 #include <X11/extensions/xtraplib.h>
44 #include <X11/extensions/xtraplibp.h>
45
46 int XEAddRequestCB(XETC *tc, CARD8 req, void_function func, BYTE *data)
47 {
48     if (!tc->values.req_cb)
49     {   /* This is the first time for this particular TC, need to malloc */
50         if ((tc->values.req_cb =
51             (XETrapCB *)XtCalloc(256L,sizeof(XETrapCB))) == NULL)
52         {
53             /* XtCalloc already reported the error */
54             return(False);
55         }
56     }
57     tc->values.req_cb[req].func = func;
58     tc->values.req_cb[req].data = data;
59
60     return(True);
61 }
62
63 int XEAddRequestCBs(XETC *tc, ReqFlags req_flags, void_function func,
64     BYTE *data)
65 {
66     int i;
67     int status = True;
68
69     for (i=0; i<=255L; i++)
70     {
71         if (BitIsTrue(req_flags, i))
72         {
73             status = XEAddRequestCB(tc, (CARD8)i, func, data);
74         }
75     }
76     return(status);
77 }
78 \f
79 int XEAddEventCB(XETC *tc, CARD8 evt, void_function func, BYTE *data)
80 {
81     if (!tc->values.evt_cb)
82     {   /* This is the first time for this particular TC, need to malloc */
83         if ((tc->values.evt_cb = 
84             (XETrapCB *)XtCalloc(XETrapCoreEvents,sizeof(XETrapCB))) == NULL)
85         {
86             /* XtCalloc already reported the error */
87             return(False);
88         }
89     }
90     tc->values.evt_cb[evt].func = func;
91     tc->values.evt_cb[evt].data = data;
92
93     return(True);
94 }
95
96 int XEAddEventCBs(XETC *tc, EventFlags evt_flags, void_function func,
97     BYTE *data)
98 {
99     int i;
100     int status = True;
101
102     for (i=KeyPress; i<=MotionNotify; i++)
103     {
104         if (BitIsTrue(evt_flags, i))
105         {
106             status = XEAddEventCB(tc, (CARD8)i, func, data);
107         }
108     }
109     return(status);
110 }
111 \f
112 void XERemoveRequestCB(XETC *tc, CARD8 req)
113 {
114     if (!tc->values.req_cb)
115     {   /* We gotta problem!  CB struct not allocated! */
116         return;
117     }
118     tc->values.req_cb[req].func = (void_function)NULL;
119     tc->values.req_cb[req].data = (BYTE *)NULL;
120     return;
121 }
122 void XERemoveRequestCBs(XETC *tc, ReqFlags req_flags)
123 {
124     int i;
125
126     for (i=0; i<=255L; i++)
127     {
128         if (BitIsTrue(req_flags, i))
129         {
130             XERemoveRequestCB(tc, (CARD8)i);
131         }
132     }
133 }
134
135 void XERemoveAllRequestCBs(XETC *tc)
136 {
137     if (!tc->values.req_cb)
138     {   /* We gotta problem!  CB struct not allocated! */
139         return;
140     }
141     XtFree((XtPointer)tc->values.req_cb);
142 }
143
144 void XERemoveEventCB(XETC *tc, CARD8 evt)
145 {
146     if (!tc->values.evt_cb)
147     {   /* We gotta problem!  CB struct not allocated! */
148         return;
149     }
150     tc->values.evt_cb[evt].func = (void_function)NULL;
151     tc->values.evt_cb[evt].data = (BYTE *)NULL;
152     return;
153 }
154
155 void XERemoveEventCBs(XETC *tc, EventFlags evt_flags)
156 {
157     int i;
158
159     for (i=KeyPress; i<=MotionNotify; i++)
160     {
161         if (BitIsTrue(evt_flags, i))
162         {
163             XERemoveEventCB(tc, (CARD8)i);
164         }
165     }
166 }
167
168 void XERemoveAllEventCBs(XETC *tc)
169 {
170     if (!tc->values.evt_cb)
171     {   /* We gotta problem!  CB struct not allocated! */
172         return;
173     }
174     XtFree((XtPointer)tc->values.evt_cb);
175 }