| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#include "tkInt.h" |
| 17 |
#include "tkPort.h" |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
typedef struct TkToplevelFocusInfo { |
| 26 |
TkWindow *topLevelPtr; |
| 27 |
TkWindow *focusWinPtr; |
| 28 |
|
| 29 |
|
| 30 |
struct TkToplevelFocusInfo *nextPtr; |
| 31 |
|
| 32 |
|
| 33 |
} ToplevelFocusInfo; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
typedef struct TkDisplayFocusInfo { |
| 52 |
TkDisplay *dispPtr; |
| 53 |
|
| 54 |
struct TkWindow *focusWinPtr; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
struct TkWindow *focusOnMapPtr; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
int forceFocus; |
| 66 |
|
| 67 |
|
| 68 |
unsigned long focusSerial; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
struct TkDisplayFocusInfo *nextPtr; |
| 74 |
|
| 75 |
|
| 76 |
} DisplayFocusInfo; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
#define GENERATED_EVENT_MAGIC ((Bool) 0x547321ac) |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
static DisplayFocusInfo *FindDisplayFocusInfo _ANSI_ARGS_((TkMainInfo *mainPtr, |
| 93 |
TkDisplay *dispPtr)); |
| 94 |
static void FocusMapProc _ANSI_ARGS_((ClientData clientData, |
| 95 |
XEvent *eventPtr)); |
| 96 |
static void GenerateFocusEvents _ANSI_ARGS_((TkWindow *sourcePtr, |
| 97 |
TkWindow *destPtr)); |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
int |
| 117 |
Tk_FocusObjCmd(clientData, interp, objc, objv) |
| 118 |
ClientData clientData; |
| 119 |
|
| 120 |
Tcl_Interp *interp; |
| 121 |
int objc; |
| 122 |
Tcl_Obj *CONST objv[]; |
| 123 |
{ |
| 124 |
static CONST char *focusOptions[] = { |
| 125 |
"-displayof", "-force", "-lastfor", (char *) NULL |
| 126 |
}; |
| 127 |
Tk_Window tkwin = (Tk_Window) clientData; |
| 128 |
TkWindow *winPtr = (TkWindow *) clientData; |
| 129 |
TkWindow *newPtr, *focusWinPtr, *topLevelPtr; |
| 130 |
ToplevelFocusInfo *tlFocusPtr; |
| 131 |
char *windowName; |
| 132 |
int index; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
if (objc == 1) { |
| 139 |
focusWinPtr = TkGetFocusWin(winPtr); |
| 140 |
if (focusWinPtr != NULL) { |
| 141 |
Tcl_SetResult(interp, focusWinPtr->pathName, TCL_STATIC); |
| 142 |
} |
| 143 |
return TCL_OK; |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
if (objc == 2) { |
| 152 |
windowName = Tcl_GetStringFromObj(objv[1], (int *) NULL); |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
if (windowName[0] == '\0') { |
| 159 |
return TCL_OK; |
| 160 |
} |
| 161 |
if (windowName[0] == '.') { |
| 162 |
newPtr = (TkWindow *) Tk_NameToWindow(interp, windowName, tkwin); |
| 163 |
if (newPtr == NULL) { |
| 164 |
return TCL_ERROR; |
| 165 |
} |
| 166 |
if (!(newPtr->flags & TK_ALREADY_DEAD)) { |
| 167 |
TkSetFocusWin(newPtr, 0); |
| 168 |
} |
| 169 |
return TCL_OK; |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
if (Tcl_GetIndexFromObj(interp, objv[1], focusOptions, "option", 0, |
| 174 |
&index) != TCL_OK) { |
| 175 |
return TCL_ERROR; |
| 176 |
} |
| 177 |
if (objc != 3) { |
| 178 |
Tcl_WrongNumArgs(interp, 2, objv, "window"); |
| 179 |
return TCL_ERROR; |
| 180 |
} |
| 181 |
switch (index) { |
| 182 |
case 0: { |
| 183 |
windowName = Tcl_GetStringFromObj(objv[2], (int *) NULL); |
| 184 |
newPtr = (TkWindow *) Tk_NameToWindow(interp, windowName, tkwin); |
| 185 |
if (newPtr == NULL) { |
| 186 |
return TCL_ERROR; |
| 187 |
} |
| 188 |
newPtr = TkGetFocusWin(newPtr); |
| 189 |
if (newPtr != NULL) { |
| 190 |
Tcl_SetResult(interp, newPtr->pathName, TCL_STATIC); |
| 191 |
} |
| 192 |
break; |
| 193 |
} |
| 194 |
case 1: { |
| 195 |
windowName = Tcl_GetStringFromObj(objv[2], (int *) NULL); |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
if (windowName[0] == '\0') { |
| 202 |
return TCL_OK; |
| 203 |
} |
| 204 |
newPtr = (TkWindow *) Tk_NameToWindow(interp, windowName, tkwin); |
| 205 |
if (newPtr == NULL) { |
| 206 |
return TCL_ERROR; |
| 207 |
} |
| 208 |
TkSetFocusWin(newPtr, 1); |
| 209 |
break; |
| 210 |
} |
| 211 |
case 2: { |
| 212 |
windowName = Tcl_GetStringFromObj(objv[2], (int *) NULL); |
| 213 |
newPtr = (TkWindow *) Tk_NameToWindow(interp, windowName, tkwin); |
| 214 |
if (newPtr == NULL) { |
| 215 |
return TCL_ERROR; |
| 216 |
} |
| 217 |
for (topLevelPtr = newPtr; topLevelPtr != NULL; |
| 218 |
topLevelPtr = topLevelPtr->parentPtr) { |
| 219 |
if (topLevelPtr->flags & TK_TOP_HIERARCHY) { |
| 220 |
for (tlFocusPtr = newPtr->mainPtr->tlFocusPtr; |
| 221 |
tlFocusPtr != NULL; |
| 222 |
tlFocusPtr = tlFocusPtr->nextPtr) { |
| 223 |
if (tlFocusPtr->topLevelPtr == topLevelPtr) { |
| 224 |
Tcl_SetResult(interp, |
| 225 |
tlFocusPtr->focusWinPtr->pathName, |
| 226 |
TCL_STATIC); |
| 227 |
return TCL_OK; |
| 228 |
} |
| 229 |
} |
| 230 |
Tcl_SetResult(interp, topLevelPtr->pathName, TCL_STATIC); |
| 231 |
return TCL_OK; |
| 232 |
} |
| 233 |
} |
| 234 |
break; |
| 235 |
} |
| 236 |
default: { |
| 237 |
panic("bad const entries to focusOptions in focus command"); |
| 238 |
} |
| 239 |
} |
| 240 |
return TCL_OK; |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
int |
| 263 |
TkFocusFilterEvent(winPtr, eventPtr) |
| 264 |
TkWindow *winPtr; |
| 265 |
XEvent *eventPtr; |
| 266 |
|
| 267 |
{ |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
ToplevelFocusInfo *tlFocusPtr; |
| 287 |
DisplayFocusInfo *displayFocusPtr; |
| 288 |
TkDisplay *dispPtr = winPtr->dispPtr; |
| 289 |
TkWindow *newFocusPtr; |
| 290 |
int retValue, delta; |
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
if (eventPtr->xfocus.send_event == GENERATED_EVENT_MAGIC) { |
| 298 |
eventPtr->xfocus.send_event = 0; |
| 299 |
return 1; |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
if ((eventPtr->xfocus.mode == EMBEDDED_APP_WANTS_FOCUS) |
| 311 |
&& (eventPtr->type == FocusIn)) { |
| 312 |
TkSetFocusWin(winPtr, eventPtr->xfocus.detail); |
| 313 |
return 0; |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
retValue = 0; |
| 324 |
displayFocusPtr = FindDisplayFocusInfo(winPtr->mainPtr, winPtr->dispPtr); |
| 325 |
if (eventPtr->type == FocusIn) { |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
if ((eventPtr->xfocus.detail == NotifyVirtual) |
| 351 |
|| (eventPtr->xfocus.detail == NotifyNonlinearVirtual) |
| 352 |
|| (eventPtr->xfocus.detail == NotifyPointerRoot) |
| 353 |
|| (eventPtr->xfocus.detail == NotifyInferior)) { |
| 354 |
return retValue; |
| 355 |
} |
| 356 |
} else if (eventPtr->type == FocusOut) { |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
if ((eventPtr->xfocus.detail == NotifyPointer) |
| 376 |
|| (eventPtr->xfocus.detail == NotifyPointerRoot) |
| 377 |
|| (eventPtr->xfocus.detail == NotifyInferior)) { |
| 378 |
return retValue; |
| 379 |
} |
| 380 |
} else { |
| 381 |
retValue = 1; |
| 382 |
if (eventPtr->xcrossing.detail == NotifyInferior) { |
| 383 |
return retValue; |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
winPtr = TkWmFocusToplevel(winPtr); |
| 392 |
if (winPtr == NULL) { |
| 393 |
return retValue; |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
if (TkGrabState(winPtr) == TK_GRAB_EXCLUDED) { |
| 402 |
return retValue; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
delta = eventPtr->xfocus.serial - displayFocusPtr->focusSerial; |
| 419 |
if (delta < 0) { |
| 420 |
return retValue; |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
for (tlFocusPtr = winPtr->mainPtr->tlFocusPtr; tlFocusPtr != NULL; |
| 429 |
tlFocusPtr = tlFocusPtr->nextPtr) { |
| 430 |
if (tlFocusPtr->topLevelPtr == winPtr) { |
| 431 |
break; |
| 432 |
} |
| 433 |
} |
| 434 |
if (tlFocusPtr == NULL) { |
| 435 |
tlFocusPtr = (ToplevelFocusInfo *) ckalloc(sizeof(ToplevelFocusInfo)); |
| 436 |
tlFocusPtr->topLevelPtr = tlFocusPtr->focusWinPtr = winPtr; |
| 437 |
tlFocusPtr->nextPtr = winPtr->mainPtr->tlFocusPtr; |
| 438 |
winPtr->mainPtr->tlFocusPtr = tlFocusPtr; |
| 439 |
} |
| 440 |
newFocusPtr = tlFocusPtr->focusWinPtr; |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
if (newFocusPtr->flags & TK_ALREADY_DEAD) { |
| 446 |
return retValue; |
| 447 |
} |
| 448 |
|
| 449 |
if (eventPtr->type == FocusIn) { |
| 450 |
GenerateFocusEvents(displayFocusPtr->focusWinPtr, newFocusPtr); |
| 451 |
displayFocusPtr->focusWinPtr = newFocusPtr; |
| 452 |
dispPtr->focusPtr = newFocusPtr; |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
if (!(winPtr->flags & TK_EMBEDDED)) { |
| 461 |
if (eventPtr->xfocus.detail == NotifyPointer) { |
| 462 |
dispPtr->implicitWinPtr = winPtr; |
| 463 |
} else { |
| 464 |
dispPtr->implicitWinPtr = NULL; |
| 465 |
} |
| 466 |
} |
| 467 |
} else if (eventPtr->type == FocusOut) { |
| 468 |
GenerateFocusEvents(displayFocusPtr->focusWinPtr, (TkWindow *) NULL); |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
if (dispPtr->focusPtr == displayFocusPtr->focusWinPtr) { |
| 477 |
dispPtr->focusPtr = NULL; |
| 478 |
} |
| 479 |
displayFocusPtr->focusWinPtr = NULL; |
| 480 |
} else if (eventPtr->type == EnterNotify) { |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
if (eventPtr->xcrossing.focus && |
| 496 |
(displayFocusPtr->focusWinPtr == NULL) |
| 497 |
&& !(winPtr->flags & TK_EMBEDDED)) { |
| 498 |
if (dispPtr->focusDebug) { |
| 499 |
printf("Focussed implicitly on %s\n", |
| 500 |
newFocusPtr->pathName); |
| 501 |
} |
| 502 |
|
| 503 |
GenerateFocusEvents(displayFocusPtr->focusWinPtr, newFocusPtr); |
| 504 |
displayFocusPtr->focusWinPtr = newFocusPtr; |
| 505 |
dispPtr->implicitWinPtr = winPtr; |
| 506 |
dispPtr->focusPtr = newFocusPtr; |
| 507 |
} |
| 508 |
} else if (eventPtr->type == LeaveNotify) { |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
if ((dispPtr->implicitWinPtr != NULL) |
| 522 |
&& !(winPtr->flags & TK_EMBEDDED)) { |
| 523 |
if (dispPtr->focusDebug) { |
| 524 |
printf("Defocussed implicit Async\n"); |
| 525 |
} |
| 526 |
GenerateFocusEvents(displayFocusPtr->focusWinPtr, |
| 527 |
(TkWindow *) NULL); |
| 528 |
XSetInputFocus(dispPtr->display, PointerRoot, RevertToPointerRoot, |
| 529 |
CurrentTime); |
| 530 |
displayFocusPtr->focusWinPtr = NULL; |
| 531 |
dispPtr->implicitWinPtr = NULL; |
| 532 |
} |
| 533 |
} |
| 534 |
return retValue; |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
void |
| 556 |
TkSetFocusWin(winPtr, force) |
| 557 |
TkWindow *winPtr; |
| 558 |
|
| 559 |
int force; |
| 560 |
|
| 561 |
|
| 562 |
{ |
| 563 |
ToplevelFocusInfo *tlFocusPtr; |
| 564 |
DisplayFocusInfo *displayFocusPtr; |
| 565 |
TkWindow *topLevelPtr; |
| 566 |
int allMapped, serial; |
| 567 |
|
| 568 |
displayFocusPtr = FindDisplayFocusInfo(winPtr->mainPtr, winPtr->dispPtr); |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
if (winPtr == displayFocusPtr->focusWinPtr && !force) { |
| 577 |
return; |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
allMapped = 1; |
| 587 |
for (topLevelPtr = winPtr; ; topLevelPtr = topLevelPtr->parentPtr) { |
| 588 |
if (topLevelPtr == NULL) { |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
return; |
| 594 |
} |
| 595 |
if (!(topLevelPtr->flags & TK_MAPPED)) { |
| 596 |
allMapped = 0; |
| 597 |
} |
| 598 |
if (topLevelPtr->flags & TK_TOP_HIERARCHY) { |
| 599 |
break; |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
if (displayFocusPtr->focusOnMapPtr != NULL) { |
| 612 |
Tk_DeleteEventHandler( |
| 613 |
(Tk_Window) displayFocusPtr->focusOnMapPtr, |
| 614 |
StructureNotifyMask, FocusMapProc, |
| 615 |
(ClientData) displayFocusPtr->focusOnMapPtr); |
| 616 |
displayFocusPtr->focusOnMapPtr = NULL; |
| 617 |
} |
| 618 |
if (!allMapped) { |
| 619 |
Tk_CreateEventHandler((Tk_Window) winPtr, |
| 620 |
VisibilityChangeMask, FocusMapProc, |
| 621 |
(ClientData) winPtr); |
| 622 |
displayFocusPtr->focusOnMapPtr = winPtr; |
| 623 |
displayFocusPtr->forceFocus = force; |
| 624 |
return; |
| 625 |
} |
| 626 |
|
| 627 |
for (tlFocusPtr = winPtr->mainPtr->tlFocusPtr; tlFocusPtr != NULL; |
| 628 |
tlFocusPtr = tlFocusPtr->nextPtr) { |
| 629 |
if (tlFocusPtr->topLevelPtr == topLevelPtr) { |
| 630 |
break; |
| 631 |
} |
| 632 |
} |
| 633 |
if (tlFocusPtr == NULL) { |
| 634 |
tlFocusPtr = (ToplevelFocusInfo *) ckalloc(sizeof(ToplevelFocusInfo)); |
| 635 |
tlFocusPtr->topLevelPtr = topLevelPtr; |
| 636 |
tlFocusPtr->nextPtr = winPtr->mainPtr->tlFocusPtr; |
| 637 |
winPtr->mainPtr->tlFocusPtr = tlFocusPtr; |
| 638 |
} |
| 639 |
tlFocusPtr->focusWinPtr = winPtr; |
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
if ((topLevelPtr->flags & TK_EMBEDDED) |
| 655 |
&& (displayFocusPtr->focusWinPtr == NULL)) { |
| 656 |
TkpClaimFocus(topLevelPtr, force); |
| 657 |
} else if ((displayFocusPtr->focusWinPtr != NULL) || force) { |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
serial = TkpChangeFocus(TkpGetWrapperWindow(topLevelPtr), force); |
| 668 |
if (serial != 0) { |
| 669 |
displayFocusPtr->focusSerial = serial; |
| 670 |
} |
| 671 |
GenerateFocusEvents(displayFocusPtr->focusWinPtr, winPtr); |
| 672 |
displayFocusPtr->focusWinPtr = winPtr; |
| 673 |
winPtr->dispPtr->focusPtr = winPtr; |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
TkWindow * |
| 697 |
TkGetFocusWin(winPtr) |
| 698 |
TkWindow *winPtr; |
| 699 |
|
| 700 |
{ |
| 701 |
DisplayFocusInfo *displayFocusPtr; |
| 702 |
|
| 703 |
if (winPtr == NULL) { |
| 704 |
return (TkWindow *) NULL; |
| 705 |
} |
| 706 |
|
| 707 |
displayFocusPtr = FindDisplayFocusInfo(winPtr->mainPtr, winPtr->dispPtr); |
| 708 |
return displayFocusPtr->focusWinPtr; |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
TkWindow * |
| 734 |
TkFocusKeyEvent(winPtr, eventPtr) |
| 735 |
TkWindow *winPtr; |
| 736 |
|
| 737 |
XEvent *eventPtr; |
| 738 |
|
| 739 |
{ |
| 740 |
DisplayFocusInfo *displayFocusPtr; |
| 741 |
TkWindow *focusWinPtr; |
| 742 |
int focusX, focusY, vRootX, vRootY, vRootWidth, vRootHeight; |
| 743 |
|
| 744 |
displayFocusPtr = FindDisplayFocusInfo(winPtr->mainPtr, winPtr->dispPtr); |
| 745 |
focusWinPtr = displayFocusPtr->focusWinPtr; |
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
#ifdef TCL_MEM_DEBUG |
| 754 |
if (focusWinPtr != winPtr->dispPtr->focusPtr) { |
| 755 |
printf("TkFocusKeyEvent found dispPtr->focusPtr out of sync:\n"); |
| 756 |
printf("expected %s, got %s\n", |
| 757 |
(focusWinPtr != NULL) ? focusWinPtr->pathName : "??", |
| 758 |
(winPtr->dispPtr->focusPtr != NULL) ? |
| 759 |
winPtr->dispPtr->focusPtr->pathName : "??"); |
| 760 |
} |
| 761 |
#endif |
| 762 |
|
| 763 |
if ((focusWinPtr != NULL) && (focusWinPtr->mainPtr == winPtr->mainPtr)) { |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
if ((focusWinPtr->display != winPtr->display) |
| 771 |
|| (focusWinPtr->screenNum != winPtr->screenNum)) { |
| 772 |
eventPtr->xkey.x = -1; |
| 773 |
eventPtr->xkey.y = -1; |
| 774 |
} else { |
| 775 |
Tk_GetVRootGeometry((Tk_Window) focusWinPtr, &vRootX, &vRootY, |
| 776 |
&vRootWidth, &vRootHeight); |
| 777 |
Tk_GetRootCoords((Tk_Window) focusWinPtr, &focusX, &focusY); |
| 778 |
eventPtr->xkey.x = eventPtr->xkey.x_root - vRootX - focusX; |
| 779 |
eventPtr->xkey.y = eventPtr->xkey.y_root - vRootY - focusY; |
| 780 |
} |
| 781 |
eventPtr->xkey.window = focusWinPtr->window; |
| 782 |
return focusWinPtr; |
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
TkpRedirectKeyEvent(winPtr, eventPtr); |
| 792 |
return (TkWindow *) NULL; |
| 793 |
} |
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
void |
| 814 |
TkFocusDeadWindow(winPtr) |
| 815 |
register TkWindow *winPtr; |
| 816 |
|
| 817 |
{ |
| 818 |
ToplevelFocusInfo *tlFocusPtr, *prevPtr; |
| 819 |
DisplayFocusInfo *displayFocusPtr; |
| 820 |
TkDisplay *dispPtr = winPtr->dispPtr; |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
if (winPtr->mainPtr == NULL) |
| 828 |
return; |
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
displayFocusPtr = FindDisplayFocusInfo(winPtr->mainPtr, winPtr->dispPtr); |
| 836 |
for (prevPtr = NULL, tlFocusPtr = winPtr->mainPtr->tlFocusPtr; |
| 837 |
tlFocusPtr != NULL; |
| 838 |
prevPtr = tlFocusPtr, tlFocusPtr = tlFocusPtr->nextPtr) { |
| 839 |
if (winPtr == tlFocusPtr->topLevelPtr) { |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
if (dispPtr->implicitWinPtr == winPtr) { |
| 847 |
if (dispPtr->focusDebug) { |
| 848 |
printf("releasing focus to root after %s died\n", |
| 849 |
tlFocusPtr->topLevelPtr->pathName); |
| 850 |
} |
| 851 |
dispPtr->implicitWinPtr = NULL; |
| 852 |
displayFocusPtr->focusWinPtr = NULL; |
| 853 |
dispPtr->focusPtr = NULL; |
| 854 |
} |
| 855 |
if (displayFocusPtr->focusWinPtr == tlFocusPtr->focusWinPtr) { |
| 856 |
displayFocusPtr->focusWinPtr = NULL; |
| 857 |
dispPtr->focusPtr = NULL; |
| 858 |
} |
| 859 |
if (prevPtr == NULL) { |
| 860 |
winPtr->mainPtr->tlFocusPtr = tlFocusPtr->nextPtr; |
| 861 |
} else { |
| 862 |
prevPtr->nextPtr = tlFocusPtr->nextPtr; |
| 863 |
} |
| 864 |
ckfree((char *) tlFocusPtr); |
| 865 |
break; |
| 866 |
} else if (winPtr == tlFocusPtr->focusWinPtr) { |
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
tlFocusPtr->focusWinPtr = tlFocusPtr->topLevelPtr; |
| 873 |
if ((displayFocusPtr->focusWinPtr == winPtr) |
| 874 |
&& !(tlFocusPtr->topLevelPtr->flags & TK_ALREADY_DEAD)) { |
| 875 |
if (dispPtr->focusDebug) { |
| 876 |
printf("forwarding focus to %s after %s died\n", |
| 877 |
tlFocusPtr->topLevelPtr->pathName, |
| 878 |
winPtr->pathName); |
| 879 |
} |
| 880 |
GenerateFocusEvents(displayFocusPtr->focusWinPtr, |
| 881 |
tlFocusPtr->topLevelPtr); |
| 882 |
displayFocusPtr->focusWinPtr = tlFocusPtr->topLevelPtr; |
| 883 |
dispPtr->focusPtr = tlFocusPtr->topLevelPtr; |
| 884 |
} |
| 885 |
break; |
| 886 |
} |
| 887 |
} |
| 888 |
|
| 889 |
if (displayFocusPtr->focusOnMapPtr == winPtr) { |
| 890 |
displayFocusPtr->focusOnMapPtr = NULL; |
| 891 |
} |
| 892 |
} |
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
static void |
| 912 |
GenerateFocusEvents(sourcePtr, destPtr) |
| 913 |
TkWindow *sourcePtr; |
| 914 |
|
| 915 |
TkWindow *destPtr; |
| 916 |
|
| 917 |
|
| 918 |
{ |
| 919 |
XEvent event; |
| 920 |
TkWindow *winPtr; |
| 921 |
|
| 922 |
winPtr = sourcePtr; |
| 923 |
if (winPtr == NULL) { |
| 924 |
winPtr = destPtr; |
| 925 |
if (winPtr == NULL) { |
| 926 |
return; |
| 927 |
} |
| 928 |
} |
| 929 |
|
| 930 |
event.xfocus.serial = LastKnownRequestProcessed(winPtr->display); |
| 931 |
event.xfocus.send_event = GENERATED_EVENT_MAGIC; |
| 932 |
event.xfocus.display = winPtr->display; |
| 933 |
event.xfocus.mode = NotifyNormal; |
| 934 |
TkInOutEvents(&event, sourcePtr, destPtr, FocusOut, FocusIn, |
| 935 |
TCL_QUEUE_MARK); |
| 936 |
} |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
static void |
| 960 |
FocusMapProc(clientData, eventPtr) |
| 961 |
ClientData clientData; |
| 962 |
XEvent *eventPtr; |
| 963 |
{ |
| 964 |
TkWindow *winPtr = (TkWindow *) clientData; |
| 965 |
DisplayFocusInfo *displayFocusPtr; |
| 966 |
|
| 967 |
if (eventPtr->type == VisibilityNotify) { |
| 968 |
displayFocusPtr = FindDisplayFocusInfo(winPtr->mainPtr, |
| 969 |
winPtr->dispPtr); |
| 970 |
if (winPtr->dispPtr->focusDebug) { |
| 971 |
printf("auto-focussing on %s, force %d\n", winPtr->pathName, |
| 972 |
displayFocusPtr->forceFocus); |
| 973 |
} |
| 974 |
Tk_DeleteEventHandler((Tk_Window) winPtr, VisibilityChangeMask, |
| 975 |
FocusMapProc, clientData); |
| 976 |
displayFocusPtr->focusOnMapPtr = NULL; |
| 977 |
TkSetFocusWin(winPtr, displayFocusPtr->forceFocus); |
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
static DisplayFocusInfo * |
| 1000 |
FindDisplayFocusInfo(mainPtr, dispPtr) |
| 1001 |
TkMainInfo *mainPtr; |
| 1002 |
|
| 1003 |
TkDisplay *dispPtr; |
| 1004 |
|
| 1005 |
{ |
| 1006 |
DisplayFocusInfo *displayFocusPtr; |
| 1007 |
|
| 1008 |
for (displayFocusPtr = mainPtr->displayFocusPtr; |
| 1009 |
displayFocusPtr != NULL; |
| 1010 |
displayFocusPtr = displayFocusPtr->nextPtr) { |
| 1011 |
if (displayFocusPtr->dispPtr == dispPtr) { |
| 1012 |
return displayFocusPtr; |
| 1013 |
} |
| 1014 |
} |
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
displayFocusPtr = (DisplayFocusInfo *) ckalloc(sizeof(DisplayFocusInfo)); |
| 1021 |
displayFocusPtr->dispPtr = dispPtr; |
| 1022 |
displayFocusPtr->focusWinPtr = NULL; |
| 1023 |
displayFocusPtr->focusOnMapPtr = NULL; |
| 1024 |
displayFocusPtr->forceFocus = 0; |
| 1025 |
displayFocusPtr->focusSerial = 0; |
| 1026 |
displayFocusPtr->nextPtr = mainPtr->displayFocusPtr; |
| 1027 |
mainPtr->displayFocusPtr = displayFocusPtr; |
| 1028 |
return displayFocusPtr; |
| 1029 |
} |
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
void |
| 1048 |
TkFocusFree(mainPtr) |
| 1049 |
TkMainInfo *mainPtr; |
| 1050 |
|
| 1051 |
{ |
| 1052 |
DisplayFocusInfo *displayFocusPtr; |
| 1053 |
ToplevelFocusInfo *tlFocusPtr; |
| 1054 |
|
| 1055 |
while (mainPtr->displayFocusPtr != NULL) { |
| 1056 |
displayFocusPtr = mainPtr->displayFocusPtr; |
| 1057 |
mainPtr->displayFocusPtr = mainPtr->displayFocusPtr->nextPtr; |
| 1058 |
ckfree((char *) displayFocusPtr); |
| 1059 |
} |
| 1060 |
while (mainPtr->tlFocusPtr != NULL) { |
| 1061 |
tlFocusPtr = mainPtr->tlFocusPtr; |
| 1062 |
mainPtr->tlFocusPtr = mainPtr->tlFocusPtr->nextPtr; |
| 1063 |
ckfree((char *) tlFocusPtr); |
| 1064 |
} |
| 1065 |
} |