1966bf024Smrg/* $XFree86$ */
2966bf024Smrg/*****************************************************************************
3966bf024SmrgCopyright 1987, 1988, 1989, 1990, 1991 by Digital Equipment Corp., Maynard, MA
4966bf024Smrg
5966bf024SmrgPermission to use, copy, modify, and distribute this software and its
6966bf024Smrgdocumentation for any purpose and without fee is hereby granted,
7966bf024Smrgprovided that the above copyright notice appear in all copies and that
8966bf024Smrgboth that copyright notice and this permission notice appear in
9966bf024Smrgsupporting documentation, and that the name of Digital not be
10966bf024Smrgused in advertising or publicity pertaining to distribution of the
11966bf024Smrgsoftware without specific, written prior permission.
12966bf024Smrg
13966bf024SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
14966bf024SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
15966bf024SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
16966bf024SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17966bf024SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
18966bf024SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
19966bf024SmrgSOFTWARE.
20966bf024Smrg
21966bf024Smrg*****************************************************************************/
22966bf024Smrg/*
23966bf024Smrg *
24966bf024Smrg *  CONTRIBUTORS:
25966bf024Smrg *
26966bf024Smrg *      Dick Annicchiarico
27966bf024Smrg *      Robert Chesler
28966bf024Smrg *      Dan Coutu
29966bf024Smrg *      Gene Durso
30966bf024Smrg *      Marc Evans
31966bf024Smrg *      Alan Jamison
32966bf024Smrg *      Mark Henry
33966bf024Smrg *      Ken Miller
34966bf024Smrg *
35966bf024Smrg */
36966bf024Smrg/*
37966bf024Smrg * This file contains XETrap Callback initilization routines.
38966bf024Smrg * The callback data hang off of the TC and are freed as part of the
39966bf024Smrg * XEFreeTC routine.
40966bf024Smrg */
41966bf024Smrg
42966bf024Smrg#include <X11/Xos.h>
43966bf024Smrg#include <X11/extensions/xtraplib.h>
44966bf024Smrg#include <X11/extensions/xtraplibp.h>
45966bf024Smrg
46966bf024Smrgint XEAddRequestCB(XETC *tc, CARD8 req, void_function func, BYTE *data)
47966bf024Smrg{
48966bf024Smrg    if (!tc->values.req_cb)
49966bf024Smrg    {   /* This is the first time for this particular TC, need to malloc */
50966bf024Smrg        if ((tc->values.req_cb =
51966bf024Smrg            (XETrapCB *)XtCalloc(256L,sizeof(XETrapCB))) == NULL)
52966bf024Smrg        {
53966bf024Smrg            /* XtCalloc already reported the error */
54966bf024Smrg            return(False);
55966bf024Smrg        }
56966bf024Smrg    }
57966bf024Smrg    tc->values.req_cb[req].func = func;
58966bf024Smrg    tc->values.req_cb[req].data = data;
59966bf024Smrg
60966bf024Smrg    return(True);
61966bf024Smrg}
62966bf024Smrg
63966bf024Smrgint XEAddRequestCBs(XETC *tc, ReqFlags req_flags, void_function func,
64966bf024Smrg    BYTE *data)
65966bf024Smrg{
66966bf024Smrg    int i;
67966bf024Smrg    int status = True;
68966bf024Smrg
69966bf024Smrg    for (i=0; i<=255L; i++)
70966bf024Smrg    {
71966bf024Smrg        if (BitIsTrue(req_flags, i))
72966bf024Smrg        {
73966bf024Smrg            status = XEAddRequestCB(tc, (CARD8)i, func, data);
74966bf024Smrg        }
75966bf024Smrg    }
76966bf024Smrg    return(status);
77966bf024Smrg}
78966bf024Smrg
79966bf024Smrgint XEAddEventCB(XETC *tc, CARD8 evt, void_function func, BYTE *data)
80966bf024Smrg{
81966bf024Smrg    if (!tc->values.evt_cb)
82966bf024Smrg    {   /* This is the first time for this particular TC, need to malloc */
83966bf024Smrg        if ((tc->values.evt_cb =
84966bf024Smrg            (XETrapCB *)XtCalloc(XETrapCoreEvents,sizeof(XETrapCB))) == NULL)
85966bf024Smrg        {
86966bf024Smrg            /* XtCalloc already reported the error */
87966bf024Smrg            return(False);
88966bf024Smrg        }
89966bf024Smrg    }
90966bf024Smrg    tc->values.evt_cb[evt].func = func;
91966bf024Smrg    tc->values.evt_cb[evt].data = data;
92966bf024Smrg
93966bf024Smrg    return(True);
94966bf024Smrg}
95966bf024Smrg
96966bf024Smrgint XEAddEventCBs(XETC *tc, EventFlags evt_flags, void_function func,
97966bf024Smrg    BYTE *data)
98966bf024Smrg{
99966bf024Smrg    int i;
100966bf024Smrg    int status = True;
101966bf024Smrg
102966bf024Smrg    for (i=KeyPress; i<=MotionNotify; i++)
103966bf024Smrg    {
104966bf024Smrg        if (BitIsTrue(evt_flags, i))
105966bf024Smrg        {
106966bf024Smrg            status = XEAddEventCB(tc, (CARD8)i, func, data);
107966bf024Smrg        }
108966bf024Smrg    }
109966bf024Smrg    return(status);
110966bf024Smrg}
111966bf024Smrg
112966bf024Smrgvoid XERemoveRequestCB(XETC *tc, CARD8 req)
113966bf024Smrg{
114966bf024Smrg    if (!tc->values.req_cb)
115966bf024Smrg    {   /* We gotta problem!  CB struct not allocated! */
116966bf024Smrg        return;
117966bf024Smrg    }
118966bf024Smrg    tc->values.req_cb[req].func = (void_function)NULL;
119966bf024Smrg    tc->values.req_cb[req].data = (BYTE *)NULL;
120966bf024Smrg    return;
121966bf024Smrg}
122966bf024Smrgvoid XERemoveRequestCBs(XETC *tc, ReqFlags req_flags)
123966bf024Smrg{
124966bf024Smrg    int i;
125966bf024Smrg
126966bf024Smrg    for (i=0; i<=255L; i++)
127966bf024Smrg    {
128966bf024Smrg        if (BitIsTrue(req_flags, i))
129966bf024Smrg        {
130966bf024Smrg            XERemoveRequestCB(tc, (CARD8)i);
131966bf024Smrg        }
132966bf024Smrg    }
133966bf024Smrg}
134966bf024Smrg
135966bf024Smrgvoid XERemoveAllRequestCBs(XETC *tc)
136966bf024Smrg{
137966bf024Smrg    if (!tc->values.req_cb)
138966bf024Smrg    {   /* We gotta problem!  CB struct not allocated! */
139966bf024Smrg        return;
140966bf024Smrg    }
141966bf024Smrg    XtFree((XtPointer)tc->values.req_cb);
142966bf024Smrg}
143966bf024Smrg
144966bf024Smrgvoid XERemoveEventCB(XETC *tc, CARD8 evt)
145966bf024Smrg{
146966bf024Smrg    if (!tc->values.evt_cb)
147966bf024Smrg    {   /* We gotta problem!  CB struct not allocated! */
148966bf024Smrg        return;
149966bf024Smrg    }
150966bf024Smrg    tc->values.evt_cb[evt].func = (void_function)NULL;
151966bf024Smrg    tc->values.evt_cb[evt].data = (BYTE *)NULL;
152966bf024Smrg    return;
153966bf024Smrg}
154966bf024Smrg
155966bf024Smrgvoid XERemoveEventCBs(XETC *tc, EventFlags evt_flags)
156966bf024Smrg{
157966bf024Smrg    int i;
158966bf024Smrg
159966bf024Smrg    for (i=KeyPress; i<=MotionNotify; i++)
160966bf024Smrg    {
161966bf024Smrg        if (BitIsTrue(evt_flags, i))
162966bf024Smrg        {
163966bf024Smrg            XERemoveEventCB(tc, (CARD8)i);
164966bf024Smrg        }
165966bf024Smrg    }
166966bf024Smrg}
167966bf024Smrg
168966bf024Smrgvoid XERemoveAllEventCBs(XETC *tc)
169966bf024Smrg{
170966bf024Smrg    if (!tc->values.evt_cb)
171966bf024Smrg    {   /* We gotta problem!  CB struct not allocated! */
172966bf024Smrg        return;
173966bf024Smrg    }
174966bf024Smrg    XtFree((XtPointer)tc->values.evt_cb);
175966bf024Smrg}
176