| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
#include "copyright.h" |
|---|
| 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 |
#include <config.h> |
|---|
| 84 |
#include "XMenuInt.h" |
|---|
| 85 |
|
|---|
| 86 |
int |
|---|
| 87 |
XMenuActivate(display, menu, p_num, s_num, x_pos, y_pos, event_mask, data, |
|---|
| 88 |
help_callback) |
|---|
| 89 |
register Display *display; |
|---|
| 90 |
register XMenu *menu; |
|---|
| 91 |
int *p_num; |
|---|
| 92 |
int *s_num; |
|---|
| 93 |
int x_pos; |
|---|
| 94 |
int y_pos; |
|---|
| 95 |
unsigned int event_mask; |
|---|
| 96 |
char **data; |
|---|
| 97 |
void (* help_callback) (); |
|---|
| 98 |
{ |
|---|
| 99 |
int status; |
|---|
| 100 |
int orig_x; |
|---|
| 101 |
int orig_y; |
|---|
| 102 |
int ret_val; |
|---|
| 103 |
|
|---|
| 104 |
register XMPane *p_ptr; |
|---|
| 105 |
register XMPane *event_xmp; |
|---|
| 106 |
register XMPane *cur_p; |
|---|
| 107 |
register XMSelect *cur_s; |
|---|
| 108 |
XMWindow *event_xmw; |
|---|
| 109 |
XEvent event; |
|---|
| 110 |
XEvent peek_event; |
|---|
| 111 |
|
|---|
| 112 |
Bool selection = False; |
|---|
| 113 |
Bool forward = True; |
|---|
| 114 |
|
|---|
| 115 |
Window root, child; |
|---|
| 116 |
int root_x, root_y, win_x, win_y; |
|---|
| 117 |
unsigned int mask; |
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
typedef struct _xmeventque { |
|---|
| 125 |
XEvent event; |
|---|
| 126 |
struct _xmeventque *next; |
|---|
| 127 |
} XMEventQue; |
|---|
| 128 |
|
|---|
| 129 |
XMEventQue *feq = NULL; |
|---|
| 130 |
XMEventQue *feq_tmp; |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
if (menu->p_count == 0) { |
|---|
| 137 |
_XMErrorCode = XME_NOT_INIT; |
|---|
| 138 |
return(XM_FAILURE); |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
cur_p = _XMGetPanePtr(menu, *p_num); |
|---|
| 145 |
if (cur_p == NULL) { |
|---|
| 146 |
return(XM_FAILURE); |
|---|
| 147 |
} |
|---|
| 148 |
cur_p->activated = cur_p->active; |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
cur_s = _XMGetSelectionPtr(cur_p, *s_num); |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
_XMTransToOrigin(display, |
|---|
| 163 |
menu, |
|---|
| 164 |
cur_p, cur_s, |
|---|
| 165 |
x_pos, y_pos, |
|---|
| 166 |
&orig_x, &orig_y); |
|---|
| 167 |
menu->x_pos = orig_x; |
|---|
| 168 |
menu->y_pos = orig_y; |
|---|
| 169 |
|
|---|
| 170 |
if (XMenuRecompute(display, menu) == XM_FAILURE) { |
|---|
| 171 |
return(XM_FAILURE); |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 |
|
|---|
| 180 |
if (_XMWinQueFlush(display, menu, cur_p, cur_s) == _FAILURE) { |
|---|
| 181 |
return(XM_FAILURE); |
|---|
| 182 |
} |
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
for(p_ptr = menu->p_list->next; p_ptr != cur_p; p_ptr = p_ptr->next) |
|---|
| 189 |
XRaiseWindow(display, p_ptr->window); |
|---|
| 190 |
for(p_ptr = menu->p_list->prev; p_ptr != cur_p->prev; p_ptr = p_ptr->prev) |
|---|
| 191 |
XRaiseWindow(display, p_ptr->window); |
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
for ( |
|---|
| 197 |
p_ptr = menu->p_list->next; |
|---|
| 198 |
p_ptr != menu->p_list; |
|---|
| 199 |
p_ptr = p_ptr->next |
|---|
| 200 |
){ |
|---|
| 201 |
XMapSubwindows(display, p_ptr->window); |
|---|
| 202 |
} |
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
XSync(display, 0); |
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
status = XGrabPointer( |
|---|
| 218 |
display, |
|---|
| 219 |
menu->parent, |
|---|
| 220 |
True, |
|---|
| 221 |
event_mask, |
|---|
| 222 |
GrabModeAsync, |
|---|
| 223 |
GrabModeAsync, |
|---|
| 224 |
None, |
|---|
| 225 |
menu->mouse_cursor, |
|---|
| 226 |
CurrentTime |
|---|
| 227 |
); |
|---|
| 228 |
if (status == _X_FAILURE) { |
|---|
| 229 |
_XMErrorCode = XME_GRAB_MOUSE; |
|---|
| 230 |
return(XM_FAILURE); |
|---|
| 231 |
} |
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
XMapWindow(display, cur_p->window); |
|---|
| 237 |
for (p_ptr = menu->p_list->next; |
|---|
| 238 |
p_ptr != cur_p; |
|---|
| 239 |
p_ptr = p_ptr->next) |
|---|
| 240 |
XMapWindow(display, p_ptr->window); |
|---|
| 241 |
for (p_ptr = cur_p->next; |
|---|
| 242 |
p_ptr != menu->p_list; |
|---|
| 243 |
p_ptr = p_ptr->next) |
|---|
| 244 |
XMapWindow(display, p_ptr->window); |
|---|
| 245 |
|
|---|
| 246 |
XRaiseWindow(display, cur_p->window); |
|---|
| 247 |
|
|---|
| 248 |
|
|---|
| 249 |
cur_s = NULL; |
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
|
|---|
| 254 |
while (1) { |
|---|
| 255 |
XNextEvent(display, &event); |
|---|
| 256 |
switch (event.type) { |
|---|
| 257 |
case Expose: |
|---|
| 258 |
event_xmp = (XMPane *)XLookUpAssoc(display, |
|---|
| 259 |
menu->assoc_tab, |
|---|
| 260 |
event.xexpose.window); |
|---|
| 261 |
if (event_xmp == NULL) { |
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
if (menu->aeq) { |
|---|
| 266 |
feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue)); |
|---|
| 267 |
if (feq_tmp == NULL) { |
|---|
| 268 |
_XMErrorCode = XME_CALLOC; |
|---|
| 269 |
return(XM_FAILURE); |
|---|
| 270 |
} |
|---|
| 271 |
feq_tmp->event = event; |
|---|
| 272 |
feq_tmp->next = feq; |
|---|
| 273 |
feq = feq_tmp; |
|---|
| 274 |
} |
|---|
| 275 |
else if (_XMEventHandler) (*_XMEventHandler)(&event); |
|---|
| 276 |
break; |
|---|
| 277 |
} |
|---|
| 278 |
if (event_xmp->activated) { |
|---|
| 279 |
XSetWindowBackground(display, |
|---|
| 280 |
event_xmp->window, |
|---|
| 281 |
menu->bkgnd_color); |
|---|
| 282 |
} |
|---|
| 283 |
else { |
|---|
| 284 |
XSetWindowBackgroundPixmap(display, |
|---|
| 285 |
event_xmp->window, |
|---|
| 286 |
menu->inact_pixmap); |
|---|
| 287 |
} |
|---|
| 288 |
_XMRefreshPane(display, menu, event_xmp); |
|---|
| 289 |
break; |
|---|
| 290 |
case EnterNotify: |
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
|
|---|
| 295 |
|
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
event_xmw = (XMWindow *)XLookUpAssoc(display, |
|---|
| 299 |
menu->assoc_tab, |
|---|
| 300 |
event.xcrossing.window); |
|---|
| 301 |
if (event_xmw == NULL) break; |
|---|
| 302 |
if (event_xmw->type == SELECTION) { |
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
if (XPending(display) != 0) { |
|---|
| 308 |
XPeekEvent(display, &peek_event); |
|---|
| 309 |
if(peek_event.type == LeaveNotify) { |
|---|
| 310 |
break; |
|---|
| 311 |
} |
|---|
| 312 |
} |
|---|
| 313 |
cur_s = (XMSelect *)event_xmw; |
|---|
| 314 |
help_callback (cur_s->help_string, |
|---|
| 315 |
cur_p->serial, cur_s->serial); |
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
|
|---|
| 322 |
if (cur_p->active && cur_s->active > 0) { |
|---|
| 323 |
cur_s->activated = 1; |
|---|
| 324 |
_XMRefreshSelection(display, menu, cur_s); |
|---|
| 325 |
} |
|---|
| 326 |
} |
|---|
| 327 |
else { |
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
if (XPending(display) != 0) { |
|---|
| 333 |
XPeekEvent(display, &peek_event); |
|---|
| 334 |
if (peek_event.type == EnterNotify) break; |
|---|
| 335 |
} |
|---|
| 336 |
XQueryPointer(display, |
|---|
| 337 |
menu->parent, |
|---|
| 338 |
&root, &child, |
|---|
| 339 |
&root_x, &root_y, |
|---|
| 340 |
&win_x, &win_y, |
|---|
| 341 |
&mask); |
|---|
| 342 |
event_xmp = (XMPane *)XLookUpAssoc(display, |
|---|
| 343 |
menu->assoc_tab, |
|---|
| 344 |
child); |
|---|
| 345 |
if (event_xmp == NULL) break; |
|---|
| 346 |
if (event_xmp == cur_p) break; |
|---|
| 347 |
if (event_xmp->serial > cur_p->serial) forward = True; |
|---|
| 348 |
else forward = False; |
|---|
| 349 |
p_ptr = cur_p; |
|---|
| 350 |
while (p_ptr != event_xmp) { |
|---|
| 351 |
if (forward) p_ptr = p_ptr->next; |
|---|
| 352 |
else p_ptr = p_ptr->prev; |
|---|
| 353 |
XRaiseWindow(display, p_ptr->window); |
|---|
| 354 |
} |
|---|
| 355 |
if (cur_p->activated) { |
|---|
| 356 |
cur_p->activated = False; |
|---|
| 357 |
XSetWindowBackgroundPixmap(display, |
|---|
| 358 |
cur_p->window, |
|---|
| 359 |
menu->inact_pixmap); |
|---|
| 360 |
_XMRefreshPane(display, menu, cur_p); |
|---|
| 361 |
} |
|---|
| 362 |
if (event_xmp->active) event_xmp->activated = True; |
|---|
| 363 |
#if 1 |
|---|
| 364 |
|
|---|
| 365 |
|
|---|
| 366 |
|
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
|
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
XSetWindowBackground(display, |
|---|
| 373 |
event_xmp->window, |
|---|
| 374 |
menu->bkgnd_color); |
|---|
| 375 |
_XMRefreshPane(display, menu, event_xmp); |
|---|
| 376 |
#endif |
|---|
| 377 |
cur_p = event_xmp; |
|---|
| 378 |
} |
|---|
| 379 |
break; |
|---|
| 380 |
case LeaveNotify: |
|---|
| 381 |
event_xmw = (XMWindow *)XLookUpAssoc( |
|---|
| 382 |
display, |
|---|
| 383 |
menu->assoc_tab, |
|---|
| 384 |
event.xcrossing.window |
|---|
| 385 |
); |
|---|
| 386 |
if (event_xmw == NULL) break; |
|---|
| 387 |
if(cur_s == NULL) break; |
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
if (cur_s->activated) { |
|---|
| 394 |
cur_s->activated = False; |
|---|
| 395 |
_XMRefreshSelection(display, menu, cur_s); |
|---|
| 396 |
} |
|---|
| 397 |
cur_s = NULL; |
|---|
| 398 |
break; |
|---|
| 399 |
|
|---|
| 400 |
case ButtonPress: |
|---|
| 401 |
case ButtonRelease: |
|---|
| 402 |
*p_num = cur_p->serial; |
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
if (cur_s != NULL) { |
|---|
| 407 |
|
|---|
| 408 |
|
|---|
| 409 |
|
|---|
| 410 |
*s_num = cur_s->serial; |
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
|
|---|
| 416 |
if (cur_s->activated) { |
|---|
| 417 |
*data = cur_s->data; |
|---|
| 418 |
ret_val = XM_SUCCESS; |
|---|
| 419 |
} |
|---|
| 420 |
else { |
|---|
| 421 |
ret_val = XM_IA_SELECT; |
|---|
| 422 |
} |
|---|
| 423 |
} |
|---|
| 424 |
else { |
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
ret_val = XM_NO_SELECT; |
|---|
| 429 |
} |
|---|
| 430 |
selection = True; |
|---|
| 431 |
break; |
|---|
| 432 |
default: |
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 |
if (menu->aeq) { |
|---|
| 437 |
feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue)); |
|---|
| 438 |
if (feq_tmp == NULL) { |
|---|
| 439 |
_XMErrorCode = XME_CALLOC; |
|---|
| 440 |
return(XM_FAILURE); |
|---|
| 441 |
} |
|---|
| 442 |
feq_tmp->event = event; |
|---|
| 443 |
feq_tmp->next = feq; |
|---|
| 444 |
feq = feq_tmp; |
|---|
| 445 |
} |
|---|
| 446 |
else if (_XMEventHandler) (*_XMEventHandler)(&event); |
|---|
| 447 |
} |
|---|
| 448 |
|
|---|
| 449 |
|
|---|
| 450 |
|
|---|
| 451 |
if (selection == True) break; |
|---|
| 452 |
} |
|---|
| 453 |
|
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 |
|
|---|
| 457 |
for ( p_ptr = menu->p_list->next; |
|---|
| 458 |
p_ptr != menu->p_list; |
|---|
| 459 |
p_ptr = p_ptr->next) |
|---|
| 460 |
{ |
|---|
| 461 |
XUnmapWindow(display, p_ptr->window); |
|---|
| 462 |
} |
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
XUngrabPointer(display, CurrentTime); |
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
|
|---|
| 471 |
|
|---|
| 472 |
|
|---|
| 473 |
|
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
if (cur_s != NULL) cur_s->activated = 0; |
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
|
|---|
| 482 |
cur_p->activated = 0; |
|---|
| 483 |
XSetWindowBackgroundPixmap(display, cur_p->window, menu->inact_pixmap); |
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
XSync(display, 0); |
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
while (QLength(display)) { |
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 |
XNextEvent(display, &event); |
|---|
| 498 |
|
|---|
| 499 |
|
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 |
switch (event.type) { |
|---|
| 504 |
case Expose: |
|---|
| 505 |
case EnterNotify: |
|---|
| 506 |
case LeaveNotify: |
|---|
| 507 |
case ButtonPress: |
|---|
| 508 |
case ButtonRelease: |
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
event_xmp = (XMPane *)XLookUpAssoc( |
|---|
| 515 |
display, |
|---|
| 516 |
menu->assoc_tab, |
|---|
| 517 |
event.xbutton.window |
|---|
| 518 |
); |
|---|
| 519 |
if (event_xmp != NULL) continue; |
|---|
| 520 |
default: |
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 |
|
|---|
| 524 |
|
|---|
| 525 |
feq_tmp = (XMEventQue *)malloc(sizeof(XMEventQue)); |
|---|
| 526 |
if (feq_tmp == NULL) { |
|---|