| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifdef WIN32 |
| 17 |
|
| 18 |
#include "tkInt.h" |
| 19 |
|
| 20 |
#ifdef __WIN32__ |
| 21 |
#include "tkWinInt.h" |
| 22 |
#endif |
| 23 |
|
| 24 |
#if defined(MAC_TCL) |
| 25 |
#include "tkMacInt.h" |
| 26 |
#define Cursor XCursor |
| 27 |
#endif |
| 28 |
|
| 29 |
#if defined(MAC_OSX_TK) |
| 30 |
#include "tkMacOSXInt.h" |
| 31 |
#define Cursor XCursor |
| 32 |
#endif |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#define ALL_BUTTONS \ |
| 40 |
(Button1Mask|Button2Mask|Button3Mask|Button4Mask|Button5Mask) |
| 41 |
static unsigned int buttonMasks[] = { |
| 42 |
Button1Mask, Button2Mask, Button3Mask, Button4Mask, Button5Mask |
| 43 |
}; |
| 44 |
#define ButtonMask(b) (buttonMasks[(b)-Button1]) |
| 45 |
|
| 46 |
typedef struct ThreadSpecificData { |
| 47 |
TkWindow *grabWinPtr; |
| 48 |
|
| 49 |
int lastState; |
| 50 |
XPoint lastPos; |
| 51 |
TkWindow *lastWinPtr; |
| 52 |
TkWindow *restrictWinPtr; |
| 53 |
|
| 54 |
TkWindow *cursorWinPtr; |
| 55 |
|
| 56 |
} ThreadSpecificData; |
| 57 |
static Tcl_ThreadDataKey dataKey; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
static int GenerateEnterLeave _ANSI_ARGS_((TkWindow *winPtr, |
| 64 |
int x, int y, int state)); |
| 65 |
static void InitializeEvent _ANSI_ARGS_((XEvent* eventPtr, |
| 66 |
TkWindow *winPtr, int type, int x, int y, |
| 67 |
int state, int detail)); |
| 68 |
static void UpdateCursor _ANSI_ARGS_((TkWindow *winPtr)); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
static void |
| 87 |
InitializeEvent(eventPtr, winPtr, type, x, y, state, detail) |
| 88 |
XEvent* eventPtr; |
| 89 |
TkWindow *winPtr; |
| 90 |
int type; |
| 91 |
int x, y; |
| 92 |
int state; |
| 93 |
int detail; |
| 94 |
{ |
| 95 |
eventPtr->type = type; |
| 96 |
eventPtr->xany.serial = LastKnownRequestProcessed(winPtr->display); |
| 97 |
eventPtr->xany.send_event = False; |
| 98 |
eventPtr->xany.display = winPtr->display; |
| 99 |
|
| 100 |
eventPtr->xcrossing.root = RootWindow(winPtr->display, winPtr->screenNum); |
| 101 |
eventPtr->xcrossing.time = TkpGetMS(); |
| 102 |
eventPtr->xcrossing.x_root = x; |
| 103 |
eventPtr->xcrossing.y_root = y; |
| 104 |
|
| 105 |
switch (type) { |
| 106 |
case EnterNotify: |
| 107 |
case LeaveNotify: |
| 108 |
eventPtr->xcrossing.mode = NotifyNormal; |
| 109 |
eventPtr->xcrossing.state = state; |
| 110 |
eventPtr->xcrossing.detail = detail; |
| 111 |
eventPtr->xcrossing.focus = False; |
| 112 |
break; |
| 113 |
case MotionNotify: |
| 114 |
eventPtr->xmotion.state = state; |
| 115 |
eventPtr->xmotion.is_hint = detail; |
| 116 |
break; |
| 117 |
case ButtonPress: |
| 118 |
case ButtonRelease: |
| 119 |
eventPtr->xbutton.state = state; |
| 120 |
eventPtr->xbutton.button = detail; |
| 121 |
break; |
| 122 |
} |
| 123 |
TkChangeEventWindow(eventPtr, winPtr); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
static int |
| 144 |
GenerateEnterLeave(winPtr, x, y, state) |
| 145 |
TkWindow *winPtr; |
| 146 |
int x,y; |
| 147 |
int state; |
| 148 |
{ |
| 149 |
int crossed = 0; |
| 150 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 151 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 152 |
TkWindow *restrictWinPtr = tsdPtr->restrictWinPtr; |
| 153 |
TkWindow *lastWinPtr = tsdPtr->lastWinPtr; |
| 154 |
|
| 155 |
if (winPtr != tsdPtr->lastWinPtr) { |
| 156 |
if (restrictWinPtr) { |
| 157 |
int newPos, oldPos; |
| 158 |
|
| 159 |
newPos = TkPositionInTree(winPtr, restrictWinPtr); |
| 160 |
oldPos = TkPositionInTree(lastWinPtr, restrictWinPtr); |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
if ((newPos != oldPos) && ((newPos == TK_GRAB_IN_TREE) |
| 168 |
|| (oldPos == TK_GRAB_IN_TREE))) { |
| 169 |
XEvent event; |
| 170 |
int type, detail; |
| 171 |
|
| 172 |
if (newPos == TK_GRAB_IN_TREE) { |
| 173 |
type = EnterNotify; |
| 174 |
} else { |
| 175 |
type = LeaveNotify; |
| 176 |
} |
| 177 |
if ((oldPos == TK_GRAB_ANCESTOR) |
| 178 |
|| (newPos == TK_GRAB_ANCESTOR)) { |
| 179 |
detail = NotifyAncestor; |
| 180 |
} else { |
| 181 |
detail = NotifyVirtual; |
| 182 |
} |
| 183 |
InitializeEvent(&event, restrictWinPtr, type, x, y, |
| 184 |
state, detail); |
| 185 |
Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); |
| 186 |
} |
| 187 |
|
| 188 |
} else { |
| 189 |
TkWindow *targetPtr; |
| 190 |
|
| 191 |
if ((lastWinPtr == NULL) |
| 192 |
|| (lastWinPtr->window == None)) { |
| 193 |
targetPtr = winPtr; |
| 194 |
} else { |
| 195 |
targetPtr = lastWinPtr; |
| 196 |
} |
| 197 |
|
| 198 |
if (targetPtr && (targetPtr->window != None)) { |
| 199 |
XEvent event; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
InitializeEvent(&event, targetPtr, LeaveNotify, x, y, state, |
| 206 |
NotifyNormal); |
| 207 |
|
| 208 |
TkInOutEvents(&event, lastWinPtr, winPtr, LeaveNotify, |
| 209 |
EnterNotify, TCL_QUEUE_TAIL); |
| 210 |
crossed = 1; |
| 211 |
} |
| 212 |
} |
| 213 |
tsdPtr->lastWinPtr = winPtr; |
| 214 |
} |
| 215 |
|
| 216 |
return crossed; |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
void |
| 237 |
Tk_UpdatePointer(tkwin, x, y, state) |
| 238 |
Tk_Window tkwin; |
| 239 |
|
| 240 |
int x, y; |
| 241 |
int state; |
| 242 |
{ |
| 243 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 244 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 245 |
TkWindow *winPtr = (TkWindow *)tkwin; |
| 246 |
TkWindow *targetWinPtr; |
| 247 |
XPoint pos; |
| 248 |
XEvent event; |
| 249 |
int changes = (state ^ tsdPtr->lastState) & ALL_BUTTONS; |
| 250 |
int type, b, mask; |
| 251 |
|
| 252 |
pos.x = x; |
| 253 |
pos.y = y; |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
tsdPtr->lastState = (state & ~ALL_BUTTONS) | (tsdPtr->lastState |
| 261 |
& ALL_BUTTONS); |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
if (GenerateEnterLeave(winPtr, x, y, tsdPtr->lastState)) { |
| 270 |
tsdPtr->lastPos = pos; |
| 271 |
} |
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
for (b = Button1; b <= Button3; b++) { |
| 279 |
mask = ButtonMask(b); |
| 280 |
if (changes & mask) { |
| 281 |
if (state & mask) { |
| 282 |
type = ButtonPress; |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
if (!tsdPtr->restrictWinPtr) { |
| 290 |
if (!tsdPtr->grabWinPtr) { |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
tsdPtr->restrictWinPtr = winPtr; |
| 297 |
TkpSetCapture(tsdPtr->restrictWinPtr); |
| 298 |
|
| 299 |
} else if ((tsdPtr->lastState & ALL_BUTTONS) == 0) { |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
if (TkPositionInTree(winPtr, tsdPtr->grabWinPtr) |
| 307 |
== TK_GRAB_IN_TREE) { |
| 308 |
tsdPtr->restrictWinPtr = winPtr; |
| 309 |
} else { |
| 310 |
tsdPtr->restrictWinPtr = tsdPtr->grabWinPtr; |
| 311 |
} |
| 312 |
TkpSetCapture(tsdPtr->restrictWinPtr); |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
} else { |
| 317 |
type = ButtonRelease; |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
if ((tsdPtr->lastState & ALL_BUTTONS) == mask) { |
| 326 |
if (!tsdPtr->grabWinPtr) { |
| 327 |
TkpSetCapture(NULL); |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
if (tsdPtr->restrictWinPtr) { |
| 338 |
InitializeEvent(&event, tsdPtr->restrictWinPtr, type, x, y, |
| 339 |
tsdPtr->lastState, b); |
| 340 |
Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); |
| 341 |
tsdPtr->lastState &= ~mask; |
| 342 |
tsdPtr->lastWinPtr = tsdPtr->restrictWinPtr; |
| 343 |
tsdPtr->restrictWinPtr = NULL; |
| 344 |
|
| 345 |
GenerateEnterLeave(winPtr, x, y, tsdPtr->lastState); |
| 346 |
tsdPtr->lastPos = pos; |
| 347 |
continue; |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
if (tsdPtr->restrictWinPtr) { |
| 359 |
targetWinPtr = tsdPtr->restrictWinPtr; |
| 360 |
} else if (tsdPtr->grabWinPtr && !winPtr) { |
| 361 |
targetWinPtr = tsdPtr->grabWinPtr; |
| 362 |
} else { |
| 363 |
targetWinPtr = winPtr; |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
if (winPtr != NULL) { |
| 371 |
InitializeEvent(&event, targetWinPtr, type, x, y, |
| 372 |
tsdPtr->lastState, b); |
| 373 |
Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
tsdPtr->lastState = (type == ButtonPress) |
| 381 |
? (tsdPtr->lastState | mask) : (tsdPtr->lastState & ~mask); |
| 382 |
tsdPtr->lastPos = pos; |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
if (tsdPtr->restrictWinPtr) { |
| 391 |
targetWinPtr = tsdPtr->restrictWinPtr; |
| 392 |
} else if (tsdPtr->grabWinPtr) { |
| 393 |
targetWinPtr = (TkPositionInTree(winPtr, tsdPtr->grabWinPtr) |
| 394 |
== TK_GRAB_IN_TREE) ? winPtr : tsdPtr->grabWinPtr; |
| 395 |
} else { |
| 396 |
targetWinPtr = winPtr; |
| 397 |
} |
| 398 |
UpdateCursor(targetWinPtr); |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
if (tsdPtr->lastPos.x != pos.x || tsdPtr->lastPos.y != pos.y) { |
| 406 |
if (tsdPtr->restrictWinPtr) { |
| 407 |
targetWinPtr = tsdPtr->restrictWinPtr; |
| 408 |
} else if (tsdPtr->grabWinPtr && !winPtr) { |
| 409 |
targetWinPtr = tsdPtr->grabWinPtr; |
| 410 |
} |
| 411 |
|
| 412 |
if (targetWinPtr != NULL) { |
| 413 |
InitializeEvent(&event, targetWinPtr, MotionNotify, x, y, |
| 414 |
tsdPtr->lastState, NotifyNormal); |
| 415 |
Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); |
| 416 |
} |
| 417 |
tsdPtr->lastPos = pos; |
| 418 |
} |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
int |
| 441 |
XGrabPointer(display, grab_window, owner_events, event_mask, pointer_mode, |
| 442 |
keyboard_mode, confine_to, cursor, time) |
| 443 |
Display* display; |
| 444 |
Window grab_window; |
| 445 |
Bool owner_events; |
| 446 |
unsigned int event_mask; |
| 447 |
int pointer_mode; |
| 448 |
int keyboard_mode; |
| 449 |
Window confine_to; |
| 450 |
Cursor cursor; |
| 451 |
Time time; |
| 452 |
{ |
| 453 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 454 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 455 |
|
| 456 |
display->request++; |
| 457 |
tsdPtr->grabWinPtr = (TkWindow *) Tk_IdToWindow(display, grab_window); |
| 458 |
tsdPtr->restrictWinPtr = NULL; |
| 459 |
TkpSetCapture(tsdPtr->grabWinPtr); |
| 460 |
if (TkPositionInTree(tsdPtr->lastWinPtr, tsdPtr->grabWinPtr) |
| 461 |
!= TK_GRAB_IN_TREE) { |
| 462 |
UpdateCursor(tsdPtr->grabWinPtr); |
| 463 |
} |
| 464 |
return GrabSuccess; |
| 465 |
} |
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
void |
| 484 |
XUngrabPointer(display, time) |
| 485 |
Display* display; |
| 486 |
Time time; |
| 487 |
{ |
| 488 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 489 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 490 |
|
| 491 |
display->request++; |
| 492 |
tsdPtr->grabWinPtr = NULL; |
| 493 |
tsdPtr->restrictWinPtr = NULL; |
| 494 |
TkpSetCapture(NULL); |
| 495 |
UpdateCursor(tsdPtr->lastWinPtr); |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
void |
| 515 |
TkPointerDeadWindow(winPtr) |
| 516 |
TkWindow *winPtr; |
| 517 |
{ |
| 518 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 519 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 520 |
|
| 521 |
if (winPtr == tsdPtr->lastWinPtr) { |
| 522 |
tsdPtr->lastWinPtr = NULL; |
| 523 |
} |
| 524 |
if (winPtr == tsdPtr->grabWinPtr) { |
| 525 |
tsdPtr->grabWinPtr = NULL; |
| 526 |
} |
| 527 |
if (winPtr == tsdPtr->restrictWinPtr) { |
| 528 |
tsdPtr->restrictWinPtr = NULL; |
| 529 |
} |
| 530 |
if (!(tsdPtr->restrictWinPtr || tsdPtr->grabWinPtr)) { |
| 531 |
TkpSetCapture(NULL); |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
static void |
| 553 |
UpdateCursor(winPtr) |
| 554 |
TkWindow *winPtr; |
| 555 |
{ |
| 556 |
Cursor cursor = None; |
| 557 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 558 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
tsdPtr->cursorWinPtr = winPtr; |
| 567 |
while (winPtr != NULL) { |
| 568 |
if (winPtr->atts.cursor != None) { |
| 569 |
cursor = winPtr->atts.cursor; |
| 570 |
break; |
| 571 |
} else if (winPtr->flags & TK_TOP_HIERARCHY) { |
| 572 |
break; |
| 573 |
} |
| 574 |
winPtr = winPtr->parentPtr; |
| 575 |
} |
| 576 |
TkpSetCursor((TkpCursor) cursor); |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
void |
| 599 |
XDefineCursor(display, w, cursor) |
| 600 |
Display* display; |
| 601 |
Window w; |
| 602 |
Cursor cursor; |
| 603 |
{ |
| 604 |
TkWindow *winPtr = (TkWindow *)Tk_IdToWindow(display, w); |
| 605 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 606 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 607 |
|
| 608 |
if (tsdPtr->cursorWinPtr == winPtr) { |
| 609 |
UpdateCursor(winPtr); |
| 610 |
} |
| 611 |
display->request++; |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
void |
| 634 |
TkGenerateActivateEvents(winPtr, active) |
| 635 |
TkWindow *winPtr; |
| 636 |
int active; |
| 637 |
|
| 638 |
{ |
| 639 |
XEvent event; |
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
event.xany.serial = winPtr->display->request++; |
| 647 |
event.xany.send_event = False; |
| 648 |
event.xany.display = winPtr->display; |
| 649 |
event.xany.window = winPtr->window; |
| 650 |
|
| 651 |
event.xany.type = active ? ActivateNotify : DeactivateNotify; |
| 652 |
TkQueueEventForAllChildren(winPtr, &event); |
| 653 |
|
| 654 |
} |
| 655 |
|
| 656 |
#endif |