1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
/*
* Copyright (c) 1999-2003 Smithsonian Astrophysical Observatory
*/
#include <xpap.h>
#if HAVE_XT
#include <X11/Intrinsic.h>
/*
*----------------------------------------------------------------------------
*
*
* Private Routines and Data
*
*
*----------------------------------------------------------------------------
*/
/*
*
* record struct for maintining Xt info in Xt select loop
*
*/
typedef struct xpaxtrec{
int fd;
void *client_data;
XtInputId id;
} *XPAXt, XPAXtRec;
/* its such a pain to maintain this, so make it global! */
static XtAppContext xpa_app=NULL;
/*
*----------------------------------------------------------------------------
*
* Routine: XPAXtHandler
*
* Purpose: handle one request for an xpaset or xpaget
*
* Return: none
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static void
XPAXtHandler (XtPointer client_data, int *fd, XtInputId *id)
#else
static void XPAXtHandler(client_data, fd, id)
XtPointer client_data;
int *fd;
XtInputId *id;
#endif
{
XPAXt xptr = (XPAXt)client_data;
if( (xptr == NULL) || (xptr->client_data == NULL) )
return;
XPAHandler((XPA)xptr->client_data, xptr->fd);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAXtEnableOneInput
*
* Purpose: Enable 1 XPA entry from the Xt event loop
*
* Results: none
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static void
XPAXtEnableOneInput (void *client_data)
#else
static void XPAXtEnableOneInput(client_data)
void *client_data;
#endif
{
XPAXt xptr = (XPAXt)client_data;
if( xptr == NULL )
return;
if( xptr->id != (XtInputId)NULL )
return;
if( xpa_app == NULL ){
xptr->id = XtAddInput(xptr->fd,
(XtPointer)XtInputReadMask,
(XtInputCallbackProc)XPAXtHandler,
(XtPointer)xptr);
}
else{
xptr->id = XtAppAddInput(xpa_app, xptr->fd,
(XtPointer)XtInputReadMask,
(XtInputCallbackProc)XPAXtHandler,
(XtPointer)xptr);
}
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAXtDisableOneInput
*
* Purpose: Disable 1 XPA entry from the Xt event loop
*
* Results: none
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static void
XPAXtDisableOneInput (void *client_data)
#else
static void XPAXtDisableOneInput(client_data)
void *client_data;
#endif
{
XPAXt xptr = (XPAXt)client_data;
if( xptr == NULL )
return;
if( xptr->id == (XtInputId)NULL )
return;
XtRemoveInput(xptr->id);
xptr->id = (XtInputId)NULL;
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAXtAddOneInput
*
* Purpose: Add 1 XPA entry to the Xt event loop
*
* Results: none
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static void *
XPAXtAddOneInput (void *client_data, int fd)
#else
static void *XPAXtAddOneInput(client_data, fd)
void *client_data;
int fd;
#endif
{
XPAXt xptr;
if( fd < 0 )
return(NULL);
xptr = (XPAXt)xcalloc(1, sizeof(XPAXtRec));
xptr->fd = fd;
xptr->client_data = client_data;
XPAXtEnableOneInput(xptr);
return(xptr);
}
/*
*----------------------------------------------------------------------------
*
* Routine: XPAXtDelOneInput
*
* Purpose: Delete 1 XPA entry from the Xt event loop (called by XPAFree)
*
* Results: none
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
static void
XPAXtDelOneInput (void *client_data)
#else
static void XPAXtDelOneInput(client_data)
void *client_data;
#endif
{
XPAXt xptr = (XPAXt)client_data;
if( xptr == NULL)
return;
XPAXtDisableOneInput(xptr);
xfree(xptr);
}
/*
*----------------------------------------------------------------------------
*
*
* Public Routines and Data
*
*
*----------------------------------------------------------------------------
*/
/*
*----------------------------------------------------------------------------
*
* Routine: XPAXtAddInput
*
* Purpose: Add XPA entries to the Xt event loop
*
* Results: number of xpa entried added
*
*----------------------------------------------------------------------------
*/
#ifdef ANSI_FUNC
int
XPAXtAddInput (void *app, XPA xpa)
#else
int XPAXtAddInput(app, xpa)
void *app;
XPA xpa;
#endif
{
XPA cur;
int got=0;
/* save the app context */
if( xpa_app == NULL ){
xpa_app = (XtAppContext)app;
}
/* if a specific xpa was specified, just add it */
if( xpa != NULL ){
/* remove old one */
if( xpa->seldel && xpa->selptr ){
(xpa->seldel)(xpa->selptr);
}
/* add new one */
xpa->seldel = XPAXtDelOneInput;
xpa->seladd = XPAXtAddOneInput;
xpa->selon = XPAXtEnableOneInput;
xpa->seloff = XPAXtDisableOneInput;
xpa->selptr = XPAXtAddOneInput((void *)xpa, xpa->fd);
got = 1;
}
/* otherwise set up all xpa's */
else{
for(cur=(XPA)XPAListHead(); cur!=NULL; cur=cur->next){
/* remove old one */
if( cur->seldel && cur->selptr ){
(cur->seldel)(cur->selptr);
}
/* add new one */
cur->seldel = XPAXtDelOneInput;
cur->seladd = XPAXtAddOneInput;
cur->selon = XPAXtEnableOneInput;
cur->seloff = XPAXtDisableOneInput;
cur->selptr = XPAXtAddOneInput((void *)cur, cur->fd);
got++;
}
}
return(got);
}
int xpa_xt = 1;
#else
int xpa_xt = 0;
#endif
|