| 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 |
#include "bltInt.h" |
| 30 |
|
| 31 |
#ifndef NO_BUSY |
| 32 |
#include "bltHash.h" |
| 33 |
|
| 34 |
#define BUSYDEBUG 0 |
| 35 |
|
| 36 |
#ifndef TK_REPARENTED |
| 37 |
#define TK_REPARENTED 0 |
| 38 |
#endif |
| 39 |
|
| 40 |
#define BUSY_THREAD_KEY "BLT Busy Data" |
| 41 |
|
| 42 |
typedef struct { |
| 43 |
Display *display; |
| 44 |
Tcl_Interp *interp; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
Tk_Window tkBusy; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
Tk_Window tkParent; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
Tk_Window tkRef; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
int x, y; |
| 65 |
|
| 66 |
int width, height; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
int isBusy; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
int menuBar; |
| 79 |
Tk_Cursor cursor; |
| 80 |
|
| 81 |
Blt_HashEntry *hashPtr; |
| 82 |
|
| 83 |
Blt_HashTable *tablePtr; |
| 84 |
} Busy; |
| 85 |
|
| 86 |
#ifdef WIN32 |
| 87 |
#define DEF_BUSY_CURSOR "wait" |
| 88 |
#else |
| 89 |
#define DEF_BUSY_CURSOR "watch" |
| 90 |
#endif |
| 91 |
|
| 92 |
static Tk_ConfigSpec configSpecs[] = |
| 93 |
{ |
| 94 |
{TK_CONFIG_CURSOR, "-cursor", "busyCursor", "BusyCursor", |
| 95 |
DEF_BUSY_CURSOR, Tk_Offset(Busy, cursor), TK_CONFIG_NULL_OK}, |
| 96 |
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0} |
| 97 |
}; |
| 98 |
|
| 99 |
typedef struct { |
| 100 |
Blt_HashTable busyTable; |
| 101 |
|
| 102 |
|
| 103 |
} BusyInterpData; |
| 104 |
|
| 105 |
static void BusyGeometryProc _ANSI_ARGS_((ClientData clientData, |
| 106 |
Tk_Window tkwin)); |
| 107 |
static void BusyCustodyProc _ANSI_ARGS_((ClientData clientData, Tk_Window tkwin)); |
| 108 |
|
| 109 |
static Tk_GeomMgr busyMgrInfo = |
| 110 |
{ |
| 111 |
"busy", |
| 112 |
BusyGeometryProc, |
| 113 |
BusyCustodyProc, |
| 114 |
}; |
| 115 |
|
| 116 |
|
| 117 |
static void DestroyBusy _ANSI_ARGS_((DestroyData dataPtr)); |
| 118 |
static void BusyEventProc _ANSI_ARGS_((ClientData clientData, |
| 119 |
XEvent *eventPtr)); |
| 120 |
|
| 121 |
static Tk_EventProc RefWinEventProc; |
| 122 |
static Tcl_CmdProc BusyCmd; |
| 123 |
static Tcl_InterpDeleteProc BusyInterpDeleteProc; |
| 124 |
|
| 125 |
static void |
| 126 |
ShowBusyWindow(busyPtr) |
| 127 |
Busy *busyPtr; |
| 128 |
{ |
| 129 |
if (busyPtr->tkBusy != NULL) { |
| 130 |
Tk_MapWindow(busyPtr->tkBusy); |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
XRaiseWindow(Tk_Display(busyPtr->tkBusy), |
| 137 |
Tk_WindowId(busyPtr->tkBusy)); |
| 138 |
} |
| 139 |
#ifdef WIN32 |
| 140 |
{ |
| 141 |
POINT point; |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
GetCursorPos(&point); |
| 153 |
SetCursorPos(point.x, point.y); |
| 154 |
} |
| 155 |
#endif |
| 156 |
} |
| 157 |
|
| 158 |
static void |
| 159 |
HideBusyWindow(busyPtr) |
| 160 |
Busy *busyPtr; |
| 161 |
{ |
| 162 |
if (busyPtr->tkBusy != NULL) { |
| 163 |
Tk_UnmapWindow(busyPtr->tkBusy); |
| 164 |
} |
| 165 |
#ifdef WIN32 |
| 166 |
{ |
| 167 |
POINT point; |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
GetCursorPos(&point); |
| 179 |
SetCursorPos(point.x, point.y); |
| 180 |
} |
| 181 |
#endif |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
static void |
| 206 |
BusyEventProc(clientData, eventPtr) |
| 207 |
ClientData clientData; |
| 208 |
XEvent *eventPtr; |
| 209 |
{ |
| 210 |
Busy *busyPtr = clientData; |
| 211 |
|
| 212 |
if (eventPtr->type == DestroyNotify) { |
| 213 |
busyPtr->tkBusy = NULL; |
| 214 |
Tcl_EventuallyFree(busyPtr, DestroyBusy); |
| 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 |
static void |
| 240 |
BusyCustodyProc(clientData, tkwin) |
| 241 |
ClientData clientData; |
| 242 |
Tk_Window tkwin; |
| 243 |
{ |
| 244 |
Busy *busyPtr = clientData; |
| 245 |
|
| 246 |
Tk_DeleteEventHandler(busyPtr->tkBusy, StructureNotifyMask, BusyEventProc, |
| 247 |
busyPtr); |
| 248 |
HideBusyWindow(busyPtr); |
| 249 |
busyPtr->tkBusy = NULL; |
| 250 |
Tcl_EventuallyFree(busyPtr, DestroyBusy); |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
static void |
| 271 |
BusyGeometryProc(clientData, tkwin) |
| 272 |
ClientData clientData; |
| 273 |
|
| 274 |
Tk_Window tkwin; |
| 275 |
|
| 276 |
{ |
| 277 |
|
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
static void |
| 317 |
RefWinEventProc(clientData, eventPtr) |
| 318 |
ClientData clientData; |
| 319 |
register XEvent *eventPtr; |
| 320 |
{ |
| 321 |
register Busy *busyPtr = clientData; |
| 322 |
|
| 323 |
switch (eventPtr->type) { |
| 324 |
case ReparentNotify: |
| 325 |
case DestroyNotify: |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
Tcl_EventuallyFree(busyPtr, DestroyBusy); |
| 332 |
break; |
| 333 |
|
| 334 |
case ConfigureNotify: |
| 335 |
if ((busyPtr->width != Tk_Width(busyPtr->tkRef)) || |
| 336 |
(busyPtr->height != Tk_Height(busyPtr->tkRef)) || |
| 337 |
(busyPtr->x != Tk_X(busyPtr->tkRef)) || |
| 338 |
(busyPtr->y != Tk_Y(busyPtr->tkRef))) { |
| 339 |
int x, y; |
| 340 |
|
| 341 |
busyPtr->width = Tk_Width(busyPtr->tkRef); |
| 342 |
busyPtr->height = Tk_Height(busyPtr->tkRef); |
| 343 |
busyPtr->x = Tk_X(busyPtr->tkRef); |
| 344 |
busyPtr->y = Tk_Y(busyPtr->tkRef); |
| 345 |
|
| 346 |
x = y = 0; |
| 347 |
|
| 348 |
if (busyPtr->tkParent != busyPtr->tkRef) { |
| 349 |
Tk_Window tkwin; |
| 350 |
|
| 351 |
for (tkwin = busyPtr->tkRef; (tkwin != NULL) && |
| 352 |
(!Tk_IsTopLevel(tkwin)); tkwin = Tk_Parent(tkwin)) { |
| 353 |
if (tkwin == busyPtr->tkParent) { |
| 354 |
break; |
| 355 |
} |
| 356 |
x += Tk_X(tkwin) + Tk_Changes(tkwin)->border_width; |
| 357 |
y += Tk_Y(tkwin) + Tk_Changes(tkwin)->border_width; |
| 358 |
} |
| 359 |
} |
| 360 |
#if BUSYDEBUG |
| 361 |
PurifyPrintf("menubar2: width=%d, height=%d\n", |
| 362 |
busyPtr->width, busyPtr->height); |
| 363 |
#endif |
| 364 |
if (busyPtr->tkBusy != NULL) { |
| 365 |
#if BUSYDEBUG |
| 366 |
fprintf(stderr, "busy window %s is at %d,%d %dx%d\n", |
| 367 |
Tk_PathName(busyPtr->tkBusy), |
| 368 |
x, y, busyPtr->width, busyPtr->height); |
| 369 |
#endif |
| 370 |
Tk_MoveResizeWindow(busyPtr->tkBusy, x, y, busyPtr->width, |
| 371 |
busyPtr->height); |
| 372 |
if (busyPtr->isBusy) { |
| 373 |
ShowBusyWindow(busyPtr); |
| 374 |
} |
| 375 |
} |
| 376 |
} |
| 377 |
break; |
| 378 |
|
| 379 |
case MapNotify: |
| 380 |
if ((busyPtr->tkParent != busyPtr->tkRef) && (busyPtr->isBusy)) { |
| 381 |
ShowBusyWindow(busyPtr); |
| 382 |
} |
| 383 |
break; |
| 384 |
|
| 385 |
case UnmapNotify: |
| 386 |
if (busyPtr->tkParent != busyPtr->tkRef) { |
| 387 |
HideBusyWindow(busyPtr); |
| 388 |
} |
| 389 |
break; |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
static int |
| 412 |
ConfigureBusy(interp, busyPtr, argc, argv) |
| 413 |
Tcl_Interp *interp; |
| 414 |
Busy *busyPtr; |
| 415 |
int argc; |
| •416 |
CONST char **argv; |
| 417 |
{ |
| 418 |
Tk_Cursor oldCursor; |
| 419 |
|
| 420 |
oldCursor = busyPtr->cursor; |
| •421 |
if (Blt_ConfigureWidget(interp, busyPtr->tkRef, configSpecs, argc, argv, |
| 422 |
(char *)busyPtr, 0) != TCL_OK) { |
| 423 |
return TCL_ERROR; |
| 424 |
} |
| 425 |
if (busyPtr->cursor != oldCursor) { |
| 426 |
if (busyPtr->cursor == None) { |
| 427 |
Tk_UndefineCursor(busyPtr->tkBusy); |
| 428 |
} else { |
| 429 |
Tk_DefineCursor(busyPtr->tkBusy, busyPtr->cursor); |
| 430 |
} |
| 431 |
} |
| 432 |
return TCL_OK; |
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
static Busy * |
| 465 |
CreateBusy(interp, tkRef) |
| 466 |
Tcl_Interp *interp; |
| 467 |
Tk_Window tkRef; |
| 468 |
{ |
| 469 |
Busy *busyPtr; |
| 470 |
int length; |
| 471 |
char *fmt, *name; |
| 472 |
Tk_Window tkBusy; |
| 473 |
Window parent; |
| 474 |
Tk_Window tkChild, tkParent; |
| 475 |
Tk_FakeWin *winPtr; |
| 476 |
int x, y; |
| 477 |
|
| 478 |
busyPtr = Blt_Calloc(1, sizeof(Busy)); |
| 479 |
assert(busyPtr); |
| 480 |
x = y = 0; |
| 481 |
length = strlen(Tk_Name(tkRef)); |
| 482 |
name = Blt_Malloc(length + 6); |
| 483 |
if (Tk_IsTopLevel(tkRef)) { |
| 484 |
fmt = "_Busy"; |
| 485 |
tkParent = tkRef; |
| 486 |
} else { |
| 487 |
Tk_Window tkwin; |
| 488 |
|
| 489 |
fmt = "%s_Busy"; |
| 490 |
tkParent = Tk_Parent(tkRef); |
| 491 |
for (tkwin = tkRef; (tkwin != NULL) && (!Tk_IsTopLevel(tkwin)); |
| 492 |
tkwin = Tk_Parent(tkwin)) { |
| 493 |
if (tkwin == tkParent) { |
| 494 |
break; |
| 495 |
} |
| 496 |
x += Tk_X(tkwin) + Tk_Changes(tkwin)->border_width; |
| 497 |
y += Tk_Y(tkwin) + Tk_Changes(tkwin)->border_width; |
| 498 |
} |
| 499 |
} |
| 500 |
for (tkChild = Blt_FirstChild(tkParent); tkChild != NULL; |
| 501 |
tkChild = Blt_NextChild(tkChild)) { |
| 502 |
Tk_MakeWindowExist(tkChild); |
| 503 |
} |
| 504 |
sprintf(name, fmt, Tk_Name(tkRef)); |
| 505 |
tkBusy = Tk_CreateWindow(interp, tkParent, name, (char *)NULL); |
| 506 |
Blt_Free(name); |
| 507 |
|
| 508 |
if (tkBusy == NULL) { |
| 509 |
return NULL; |
| 510 |
} |
| 511 |
Tk_MakeWindowExist(tkRef); |
| 512 |
busyPtr->display = Tk_Display(tkRef); |
| 513 |
busyPtr->interp = interp; |
| 514 |
busyPtr->tkRef = tkRef; |
| 515 |
busyPtr->tkParent = tkParent; |
| 516 |
busyPtr->tkBusy = tkBusy; |
| 517 |
busyPtr->width = Tk_Width(tkRef); |
| 518 |
busyPtr->height = Tk_Height(tkRef); |
| 519 |
busyPtr->x = Tk_X(tkRef); |
| 520 |
busyPtr->y = Tk_Y(tkRef); |
| 521 |
busyPtr->cursor = None; |
| 522 |
busyPtr->isBusy = FALSE; |
| 523 |
Tk_SetClass(tkBusy, "Busy"); |
| 524 |
#if (TK_MAJOR_VERSION > 4) |
| 525 |
Blt_SetWindowInstanceData(tkBusy, busyPtr); |
| 526 |
#endif |
| 527 |
winPtr = (Tk_FakeWin *) tkRef; |
| 528 |
if (winPtr->flags & TK_REPARENTED) { |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
#ifdef WIN32 |
| 538 |
{ |
| 539 |
HWND hWnd; |
| 540 |
RECT rect; |
| 541 |
|
| 542 |
hWnd = GetParent(Tk_GetHWND(Tk_WindowId(tkRef))); |
| 543 |
parent = (Window) hWnd; |
| 544 |
if (GetWindowRect(hWnd, &rect)) { |
| 545 |
busyPtr->width = rect.right - rect.left; |
| 546 |
busyPtr->height = rect.bottom - rect.top; |
| 547 |
#if BUSYDEBUG |
| 548 |
PurifyPrintf("menubar: width=%d, height=%d\n", |
| 549 |
busyPtr->width, busyPtr->height); |
| 550 |
#endif |
| 551 |
} |
| 552 |
} |
| 553 |
#else |
| 554 |
parent = Blt_GetParent(Tk_Display(tkRef), Tk_WindowId(tkRef)); |
| 555 |
#endif |
| 556 |
} else { |
| 557 |
parent = Tk_WindowId(tkParent); |
| 558 |
#ifdef WIN32 |
| 559 |
parent = (Window) Tk_GetHWND(parent); |
| 560 |
#endif |
| 561 |
} |
| 562 |
Blt_MakeTransparentWindowExist(tkBusy, parent, TRUE); |
| 563 |
|
| 564 |
#if BUSYDEBUG |
| 565 |
PurifyPrintf("menubar1: width=%d, height=%d\n", busyPtr->width, |
| 566 |
busyPtr->height); |
| 567 |
fprintf(stderr, "busy window %s is at %d,%d %dx%d\n", Tk_PathName(tkBusy), |
| 568 |
x, y, busyPtr->width, busyPtr->height); |
| 569 |
#endif |
| 570 |
Tk_MoveResizeWindow(tkBusy, x, y, busyPtr->width, busyPtr->height); |
| 571 |
|
| 572 |
|
| 573 |
Tk_CreateEventHandler(tkBusy, StructureNotifyMask, BusyEventProc, busyPtr); |
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
Tk_ManageGeometry(tkBusy, &busyMgrInfo, busyPtr); |
| 579 |
if (busyPtr->cursor != None) { |
| 580 |
Tk_DefineCursor(tkBusy, busyPtr->cursor); |
| 581 |
} |
| 582 |
|
| 583 |
Tk_CreateEventHandler(tkRef, StructureNotifyMask, RefWinEventProc, busyPtr); |
| 584 |
return busyPtr; |
| 585 |
} |
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
static void |
| 606 |
DestroyBusy(data) |
| 607 |
DestroyData data; |
| 608 |
{ |
| 609 |
Busy *busyPtr = (Busy *)data; |
| 610 |
|
| 611 |
Tk_FreeOptions(configSpecs, (char *)busyPtr, busyPtr->display, 0); |
| 612 |
if (busyPtr->hashPtr != NULL) { |
| 613 |
Blt_DeleteHashEntry(busyPtr->tablePtr, busyPtr->hashPtr); |
| 614 |
} |
| 615 |
Tk_DeleteEventHandler(busyPtr->tkRef, StructureNotifyMask, |
| 616 |
RefWinEventProc, busyPtr); |
| 617 |
if (busyPtr->tkBusy != NULL) { |
| 618 |
Tk_DeleteEventHandler(busyPtr->tkBusy, StructureNotifyMask, |
| 619 |
BusyEventProc, busyPtr); |
| 620 |
Tk_ManageGeometry(busyPtr->tkBusy, NULL, busyPtr); |
| 621 |
Tk_DestroyWindow(busyPtr->tkBusy); |
| 622 |
} |
| 623 |
Blt_Free(busyPtr); |
| 624 |
} |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
static int |
| 645 |
GetBusy(dataPtr, interp, pathName, busyPtrPtr) |
| 646 |
BusyInterpData *dataPtr; |
| 647 |
Tcl_Interp *interp; |
| 648 |
char *pathName; |
| 649 |
Busy **busyPtrPtr; |
| 650 |
|
| 651 |
{ |
| 652 |
Blt_HashEntry *hPtr; |
| 653 |
Tk_Window tkwin; |
| 654 |
|
| 655 |
tkwin = Tk_NameToWindow(interp, pathName, Tk_MainWindow(interp)); |
| 656 |
if (tkwin == NULL) { |
| 657 |
return TCL_ERROR; |
| 658 |
} |
| 659 |
hPtr = Blt_FindHashEntry(&dataPtr->busyTable, (char *)tkwin); |
| 660 |
if (hPtr == NULL) { |
| 661 |
Tcl_AppendResult(interp, "can't find busy window \"", pathName, "\"", |
| 662 |
(char *)NULL); |
| 663 |
return TCL_ERROR; |
| 664 |
} |
| 665 |
*busyPtrPtr = ((Busy *)Blt_GetHashValue(hPtr)); |
| 666 |
return TCL_OK; |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
static int |
| 691 |
HoldBusy(dataPtr, interp, argc, argv) |
| 692 |
BusyInterpData *dataPtr; |
| 693 |
Tcl_Interp *interp; |
| 694 |
int argc; |
| 695 |
char **argv; |
| 696 |
{ |
| 697 |
Tk_Window tkwin; |
| 698 |
Blt_HashEntry *hPtr; |
| 699 |
Busy *busyPtr; |
| 700 |
int isNew; |
| 701 |
int result; |
| 702 |
|
| 703 |
tkwin = Tk_NameToWindow(interp, argv[0], Tk_MainWindow(interp)); |
| 704 |
if (tkwin == NULL) { |
| 705 |
return TCL_ERROR; |
| 706 |
} |
| 707 |
hPtr = Blt_CreateHashEntry(&dataPtr->busyTable, (char *)tkwin, &isNew); |
| 708 |
if (isNew) { |
| 709 |
busyPtr = (Busy *)CreateBusy(interp, tkwin); |
| 710 |
if (busyPtr == NULL) { |
| 711 |
return TCL_ERROR; |
| 712 |
} |
| 713 |
Blt_SetHashValue(hPtr, (char *)busyPtr); |
| 714 |
busyPtr->hashPtr = hPtr; |
| 715 |
} else { |
| 716 |
busyPtr = (Busy *)Blt_GetHashValue(hPtr); |
| 717 |
} |
| 718 |
busyPtr->tablePtr = &dataPtr->busyTable; |
| 719 |
result = ConfigureBusy(interp, busyPtr, argc - 1, argv + 1); |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
if (Tk_IsMapped(busyPtr->tkRef)) { |
| 726 |
ShowBusyWindow(busyPtr); |
| 727 |
} else { |
| 728 |
HideBusyWindow(busyPtr); |
| 729 |
} |
| 730 |
busyPtr->isBusy = TRUE; |
| 731 |
return result; |
| 732 |
} |
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
static int |
| 752 |
StatusOp(clientData, interp, argc, argv) |
| 753 |
ClientData clientData; |
| 754 |
Tcl_Interp *interp; |
| 755 |
int argc; |
| 756 |
char **argv; |
| 757 |
{ |
| 758 |
BusyInterpData *dataPtr = clientData; |
| 759 |
Busy *busyPtr; |
| 760 |
|
| 761 |
if (GetBusy(dataPtr, interp, argv[2], &busyPtr) != TCL_OK) { |
| 762 |
return TCL_ERROR; |
| 763 |
} |
| 764 |
Tcl_Preserve(busyPtr); |
| 765 |
Blt_SetBooleanResult(interp, busyPtr->isBusy); |
| 766 |
Tcl_Release(busyPtr); |
| 767 |
return TCL_OK; |
| 768 |
} |
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
static int |
| 792 |
ForgetOp(clientData, interp, argc, argv) |
| 793 |
ClientData clientData; |
| 794 |
Tcl_Interp *interp; |
| 795 |
int argc; |
| 796 |
char **argv; |
| 797 |
{ |
| 798 |
BusyInterpData *dataPtr = clientData; |
| 799 |
Busy *busyPtr; |
| 800 |
register int i; |
| 801 |
|
| 802 |
for (i = 2; i < argc; i++) { |
| 803 |
if (GetBusy(dataPtr, interp, argv[i], &busyPtr) != TCL_OK) { |
| 804 |
return TCL_ERROR; |
| 805 |
} |
| 806 |
|
| 807 |
HideBusyWindow(busyPtr); |
| 808 |
Tcl_EventuallyFree(busyPtr, DestroyBusy); |
| 809 |
} |
| 810 |
return TCL_OK; |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
static int |
| 834 |
ReleaseOp(clientData, interp, argc, argv) |
| 835 |
ClientData clientData; |
| 836 |
Tcl_Interp *interp; |
| 837 |
int argc; |
| 838 |
char **argv; |
| 839 |
{ |
| 840 |
BusyInterpData *dataPtr = clientData; |
| 841 |
Busy *busyPtr; |
| 842 |
int i; |
| 843 |
|
| 844 |
for (i = 2; i < argc; i++) { |
| 845 |
if (GetBusy(dataPtr, interp, argv[i], &busyPtr) != TCL_OK) { |
| 846 |
return TCL_ERROR; |
| 847 |
} |
| 848 |
HideBusyWindow(busyPtr); |
| 849 |
busyPtr->isBusy = FALSE; |
| 850 |
} |
| 851 |
return TCL_OK; |
| 852 |
} |
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
static int |
| 871 |
NamesOp(clientData, interp, argc, argv) |
| 872 |
ClientData clientData; |
| 873 |
Tcl_Interp *interp; |
| 874 |
int argc; |
| 875 |
char **argv; |
| 876 |
{ |
| 877 |
BusyInterpData *dataPtr = clientData; |
| 878 |
Blt_HashEntry *hPtr; |
| 879 |
Blt_HashSearch cursor; |
| 880 |
Busy *busyPtr; |
| 881 |
|
| 882 |
for (hPtr = Blt_FirstHashEntry(&dataPtr->busyTable, &cursor); |
| 883 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 884 |
busyPtr = (Busy *)Blt_GetHashValue(hPtr); |
| 885 |
if ((argc == 2) || |
| 886 |
(Tcl_StringMatch(Tk_PathName(busyPtr->tkRef), argv[2]))) { |
| 887 |
Tcl_AppendElement(interp, Tk_PathName(busyPtr->tkRef)); |
| 888 |
} |
| 889 |
} |
| 890 |
return TCL_OK; |
| 891 |
} |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
static int |
| 910 |
BusyOp(clientData, interp, argc, argv) |
| 911 |
ClientData clientData; |
| 912 |
Tcl_Interp *interp; |
| 913 |
int argc; |
| 914 |
char **argv; |
| 915 |
{ |
| 916 |
BusyInterpData *dataPtr = clientData; |
| 917 |
Blt_HashEntry *hPtr; |
| 918 |
Blt_HashSearch cursor; |
| 919 |
Busy *busyPtr; |
| 920 |
|
| 921 |
for (hPtr = Blt_FirstHashEntry(&dataPtr->busyTable, &cursor); |
| 922 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 923 |
busyPtr = (Busy *)Blt_GetHashValue(hPtr); |
| 924 |
if (!busyPtr->isBusy) { |
| 925 |
continue; |
| 926 |
} |
| 927 |
if ((argc == 2) || |
| 928 |
(Tcl_StringMatch(Tk_PathName(busyPtr->tkRef), argv[2]))) { |
| 929 |
Tcl_AppendElement(interp, Tk_PathName(busyPtr->tkRef)); |
| 930 |
} |
| 931 |
} |
| 932 |
return TCL_OK; |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
static int |
| 955 |
HoldOp(clientData, interp, argc, argv) |
| 956 |
ClientData clientData; |
| 957 |
Tcl_Interp *interp; |
| 958 |
int argc; |
| 959 |
char **argv; |
| 960 |
{ |
| 961 |
BusyInterpData *dataPtr = clientData; |
| 962 |
register int i, count; |
| 963 |
|
| 964 |
if ((argv[1][0] == 'h') && (strcmp(argv[1], "hold") == 0)) { |
| 965 |
argc--, argv++; |
| 966 |
} |
| 967 |
for (i = 1; i < argc; i++) { |
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
for (count = i + 1; count < argc; count += 2) { |
| 972 |
if (argv[count][0] != '-') { |
| 973 |
break; |
| 974 |
} |
| 975 |
} |
| 976 |
if (count > argc) { |
| 977 |
count = argc; |
| 978 |
} |
| 979 |
if (HoldBusy(dataPtr, interp, count - i, argv + i) != TCL_OK) { |
| 980 |
return TCL_ERROR; |
| 981 |
} |
| 982 |
i = count; |
| 983 |
} |
| 984 |
return TCL_OK; |
| 985 |
} |
| 986 |
|
| 987 |
|
| 988 |
static int |
| 989 |
CgetOp(clientData, interp, argc, argv) |
| 990 |
ClientData clientData; |
| 991 |
Tcl_Interp *interp; |
| 992 |
int argc; |
| 993 |
char **argv; |
| 994 |
{ |
| 995 |
BusyInterpData *dataPtr = clientData; |
| 996 |
Busy *busyPtr; |
| 997 |
int result; |
| 998 |
|
| 999 |
if (GetBusy(dataPtr, interp, argv[2], &busyPtr) != TCL_OK) { |
| 1000 |
return TCL_ERROR; |
| 1001 |
} |
| 1002 |
Tcl_Preserve(busyPtr); |
| 1003 |
result = Tk_ConfigureValue(interp, busyPtr->tkRef, configSpecs, |
| 1004 |
(char *)busyPtr, argv[3], 0); |
| 1005 |
Tcl_Release(busyPtr); |
| 1006 |
return result; |
| 1007 |
} |
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
static int |
| 1029 |
ConfigureOp(clientData, interp, argc, argv) |
| 1030 |
ClientData clientData; |
| 1031 |
Tcl_Interp *interp; |
| 1032 |
int argc; |
| 1033 |
char **argv; |
| 1034 |
{ |
| 1035 |
BusyInterpData *dataPtr = clientData; |
| 1036 |
Busy *busyPtr; |
| 1037 |
int result; |
| 1038 |
|
| 1039 |
if (GetBusy(dataPtr, interp, argv[2], &busyPtr) != TCL_OK) { |
| 1040 |
return TCL_ERROR; |
| 1041 |
} |
| 1042 |
if (argc == 3) { |
| 1043 |
result = Tk_ConfigureInfo(interp, busyPtr->tkRef, configSpecs, |
| 1044 |
(char *)busyPtr, (char *)NULL, 0); |
| 1045 |
} else if (argc == 4) { |
| 1046 |
result = Tk_ConfigureInfo(interp, busyPtr->tkRef, configSpecs, |
| 1047 |
(char *)busyPtr, argv[3], 0); |
| 1048 |
} else { |
| 1049 |
Tcl_Preserve(busyPtr); |
| 1050 |
result = ConfigureBusy(interp, busyPtr, argc - 3, argv + 3); |
| 1051 |
Tcl_Release(busyPtr); |
| 1052 |
} |
| 1053 |
return result; |
| 1054 |
} |
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
static void |
| 1074 |
BusyInterpDeleteProc(clientData, interp) |
| 1075 |
ClientData clientData; |
| 1076 |
Tcl_Interp *interp; |
| 1077 |
{ |
| 1078 |
BusyInterpData *dataPtr = clientData; |
| 1079 |
Blt_HashEntry *hPtr; |
| 1080 |
Blt_HashSearch cursor; |
| 1081 |
Busy *busyPtr; |
| 1082 |
|
| 1083 |
for (hPtr = Blt_FirstHashEntry(&dataPtr->busyTable, &cursor); |
| 1084 |
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) { |
| 1085 |
busyPtr = (Busy *)Blt_GetHashValue(hPtr); |
| 1086 |
busyPtr->hashPtr = NULL; |
| 1087 |
DestroyBusy((DestroyData)busyPtr); |
| 1088 |
} |
| 1089 |
Blt_DeleteHashTable(&dataPtr->busyTable); |
| 1090 |
Tcl_DeleteAssocData(interp, BUSY_THREAD_KEY); |
| 1091 |
Blt_Free(dataPtr); |
| 1092 |
} |
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
static Blt_OpSpec busyOps[] = |
| 1110 |
{ |
| 1111 |
{"cget", 2, (Blt_Op)CgetOp, 4, 4, "window option",}, |
| 1112 |
{"configure", 2, (Blt_Op)ConfigureOp, 3, 0, "window ?options?...",}, |
| 1113 |
{"forget", 1, (Blt_Op)ForgetOp, 2, 0, "?window?...",}, |
| 1114 |
{"hold", 3, (Blt_Op)HoldOp, 3, 0, |
| 1115 |
"window ?options?... ?window options?...",}, |
| 1116 |
{"isbusy", 1, (Blt_Op)BusyOp, 2, 3, "?pattern?",}, |
| 1117 |
{"names", 1, (Blt_Op)NamesOp, 2, 3, "?pattern?",}, |
| 1118 |
{"release", 1, (Blt_Op)ReleaseOp, 2, 0, "?window?...",}, |
| 1119 |
{"status", 1, (Blt_Op)StatusOp, 3, 3, "window",}, |
| 1120 |
{"windows", 1, (Blt_Op)NamesOp, 2, 3, "?pattern?",}, |
| 1121 |
}; |
| 1122 |
static int nBusyOps = sizeof(busyOps) / sizeof(Blt_OpSpec); |
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
static int |
| 1141 |
BusyCmd(clientData, interp, argc, argv) |
| 1142 |
ClientData clientData; |
| 1143 |
Tcl_Interp *interp; |
| 1144 |
int argc; |
| 1145 |
char **argv; |
| 1146 |
{ |
| 1147 |
Blt_Op proc; |
| 1148 |
int result; |
| 1149 |
|
| 1150 |
if ((argc > 1) && (argv[1][0] == '.')) { |
| 1151 |
return HoldOp(clientData, interp, argc, argv); |
| 1152 |
} |
| 1153 |
proc = Blt_GetOp(interp, nBusyOps, busyOps, BLT_OP_ARG1, argc, argv, 0); |
| 1154 |
if (proc == NULL) { |
| 1155 |
return TCL_ERROR; |
| 1156 |
} |
| 1157 |
result = (*proc) (clientData, interp, argc, argv); |
| 1158 |
return result; |
| 1159 |
} |
| 1160 |
|
| 1161 |
static BusyInterpData * |
| 1162 |
GetBusyInterpData(interp) |
| 1163 |
Tcl_Interp *interp; |
| 1164 |
{ |
| 1165 |
BusyInterpData *dataPtr; |
| 1166 |
Tcl_InterpDeleteProc *proc; |
| 1167 |
|
| 1168 |
dataPtr = (BusyInterpData *) |
| 1169 |
Tcl_GetAssocData(interp, BUSY_THREAD_KEY, &proc); |
| 1170 |
if (dataPtr == NULL) { |
| 1171 |
dataPtr = Blt_Malloc(sizeof(BusyInterpData)); |
| 1172 |
assert(dataPtr); |
| 1173 |
Tcl_SetAssocData(interp, BUSY_THREAD_KEY, BusyInterpDeleteProc, |
| 1174 |
dataPtr); |
| 1175 |
Blt_InitHashTable(&dataPtr->busyTable, BLT_ONE_WORD_KEYS); |
| 1176 |
} |
| 1177 |
return dataPtr; |
| 1178 |
} |
| 1179 |
|
| 1180 |
int |
| 1181 |
Blt_BusyInit(interp) |
| 1182 |
Tcl_Interp *interp; |
| 1183 |
{ |
| 1184 |
static Blt_CmdSpec cmdSpec = {"busy", BusyCmd, }; |
| 1185 |
BusyInterpData *dataPtr; |
| 1186 |
|
| 1187 |
dataPtr = GetBusyInterpData(interp); |
| 1188 |
cmdSpec.clientData = dataPtr; |
| 1189 |
if (Blt_InitCmd(interp, "blt", &cmdSpec) == NULL) { |
| 1190 |
return TCL_ERROR; |
| 1191 |
} |
| 1192 |
return TCL_OK; |
| 1193 |
} |
| 1194 |
#endif |