| 1 |
/* |
| 2 |
* bltBusy.c -- |
| 3 |
* |
| 4 |
* This module implements busy windows for the BLT toolkit. |
| 5 |
* |
| 6 |
* Copyright 1993-1998 Lucent Technologies, Inc. |
| 7 |
* |
| 8 |
* Permission to use, copy, modify, and distribute this software and |
| 9 |
* its documentation for any purpose and without fee is hereby |
| 10 |
* granted, provided that the above copyright notice appear in all |
| 11 |
* copies and that both that the copyright notice and warranty |
| 12 |
* disclaimer appear in supporting documentation, and that the names |
| 13 |
* of Lucent Technologies any of their entities not be used in |
| 14 |
* advertising or publicity pertaining to distribution of the software |
| 15 |
* without specific, written prior permission. |
| 16 |
* |
| 17 |
* Lucent Technologies disclaims all warranties with regard to this |
| 18 |
* software, including all implied warranties of merchantability and |
| 19 |
* fitness. In no event shall Lucent Technologies be liable for any |
| 20 |
* special, indirect or consequential damages or any damages |
| 21 |
* whatsoever resulting from loss of use, data or profits, whether in |
| 22 |
* an action of contract, negligence or other tortuous action, arising |
| 23 |
* out of or in connection with the use or performance of this |
| 24 |
* software. |
| 25 |
* |
| 26 |
* The "busy" command was created by George Howlett. |
| 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; /* Display of busy window */ |
| 44 |
Tcl_Interp *interp; /* Interpreter where "busy" command was |
| 45 |
* created. It's used to key the |
| 46 |
* searches in the window hierarchy. See the |
| 47 |
* "windows" command. */ |
| 48 |
|
| 49 |
Tk_Window tkBusy; /* Busy window: Transparent window used |
| 50 |
* to block delivery of events to windows |
| 51 |
* underneath it. */ |
| 52 |
|
| 53 |
Tk_Window tkParent; /* Parent window of the busy |
| 54 |
* window. It may be the reference |
| 55 |
* window (if the reference is a |
| 56 |
* toplevel) or a mutual ancestor of |
| 57 |
* the reference window */ |
| 58 |
|
| 59 |
Tk_Window tkRef; /* Reference window of the busy window. |
| 60 |
* It's is used to manage the size and |
| 61 |
* position of the busy window. */ |
| 62 |
|
| 63 |
|
| 64 |
int x, y; /* Position of the reference window */ |
| 65 |
|
| 66 |
int width, height; /* Size of the reference window. Retained to |
| 67 |
* know if the reference window has been |
| 68 |
* reconfigured to a new size. */ |
| 69 |
|
| 70 |
int isBusy; /* Indicates whether the transparent |
| 71 |
* window should be displayed. This |
| 72 |
* can be different from what |
| 73 |
* Tk_IsMapped says because the a |
| 74 |
* sibling reference window may be |
| 75 |
* unmapped, forcing the busy window |
| 76 |
* to be also hidden. */ |
| 77 |
|
| 78 |
int menuBar; /* Menu bar flag. */ |
| 79 |
Tk_Cursor cursor; /* Cursor for the busy window. */ |
| 80 |
|
| 81 |
Blt_HashEntry *hashPtr; /* Used the delete the busy window entry |
| 82 |
* out of the global hash table. */ |
| 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; /* Hash table of busy window |
| 101 |
* structures keyed by the address of |
| 102 |
* the reference Tk window */ |
| 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", /* Name of geometry manager used by winfo */ |
| 112 |
BusyGeometryProc, /* Procedure to for new geometry requests */ |
| 113 |
BusyCustodyProc, /* Procedure when window is taken away */ |
| 114 |
}; |
| 115 |
|
| 116 |
/* Forward declarations */ |
| 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 |
* Always raise the busy window just in case new sibling |
| 133 |
* windows have been created in the meantime. Can't use |
| 134 |
* Tk_RestackWindow because it doesn't work under Win32. |
| 135 |
*/ |
| 136 |
XRaiseWindow(Tk_Display(busyPtr->tkBusy), |
| 137 |
Tk_WindowId(busyPtr->tkBusy)); |
| 138 |
} |
| 139 |
#ifdef WIN32 |
| 140 |
{ |
| 141 |
POINT point; |
| 142 |
/* |
| 143 |
* Under Win32, cursors aren't associated with windows. Tk |
| 144 |
* fakes this by watching Motion events on its windows. So Tk |
| 145 |
* will automatically change the cursor when the pointer |
| 146 |
* enters the Busy window. But Windows doesn't immediately |
| 147 |
* change the cursor; it waits for the cursor position to |
| 148 |
* change or a system call. We need to change the cursor |
| 149 |
* before the application starts processing, so set the cursor |
| 150 |
* position redundantly back to the current position. |
| 151 |
*/ |
| 152 |
GetCursorPos(&point); |
| 153 |
SetCursorPos(point.x, point.y); |
| 154 |
} |
| 155 |
#endif /* WIN32 */ |
| 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 |
* Under Win32, cursors aren't associated with windows. Tk |
| 170 |
* fakes this by watching Motion events on its windows. So Tk |
| 171 |
* will automatically change the cursor when the pointer |
| 172 |
* enters the Busy window. But Windows doesn't immediately |
| 173 |
* change the cursor: it waits for the cursor position to |
| 174 |
* change or a system call. We need to change the cursor |
| 175 |
* before the application starts processing, so set the cursor |
| 176 |
* position redundantly back to the current position. |
| 177 |
*/ |
| 178 |
GetCursorPos(&point); |
| 179 |
SetCursorPos(point.x, point.y); |
| 180 |
} |
| 181 |
#endif /* WIN32 */ |
| 182 |
} |
| 183 |
|
| 184 |
/* |
| 185 |
*---------------------------------------------------------------------- |
| 186 |
* |
| 187 |
* BusyEventProc -- |
| 188 |
* |
| 189 |
* This procedure is invoked by the Tk dispatcher for events on |
| 190 |
* the busy window itself. We're only concerned with destroy |
| 191 |
* events. |
| 192 |
* |
| 193 |
* It might be necessary (someday) to watch resize events. Right |
| 194 |
* now, I don't think there's any point in it. |
| 195 |
* |
| 196 |
* Results: |
| 197 |
* None. |
| 198 |
* |
| 199 |
* Side effects: |
| 200 |
* When a busy window is destroyed, all internal structures |
| 201 |
* associated with it released at the next idle point. |
| 202 |
* |
| 203 |
*---------------------------------------------------------------------- |
| 204 |
*/ |
| 205 |
static void |
| 206 |
BusyEventProc(clientData, eventPtr) |
| 207 |
ClientData clientData; /* Busy window record */ |
| 208 |
XEvent *eventPtr; /* Event which triggered call to routine */ |
| 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 |
* BusyCustodyProc -- |
| 223 |
* |
| 224 |
* This procedure is invoked when the busy window has been stolen |
| 225 |
* by another geometry manager. The information and memory |
| 226 |
* associated with the busy window is released. I don't know why |
| 227 |
* anyone would try to pack a busy window, but this should keep |
| 228 |
* everything sane, if it is. |
| 229 |
* |
| 230 |
* Results: |
| 231 |
* None. |
| 232 |
* |
| 233 |
* Side effects: |
| 234 |
* The Busy structure is freed at the next idle point. |
| 235 |
* |
| 236 |
* ---------------------------------------------------------------------------- |
| 237 |
*/ |
| 238 |
/* ARGSUSED */ |
| 239 |
static void |
| 240 |
BusyCustodyProc(clientData, tkwin) |
| 241 |
ClientData clientData; /* Information about the busy window. */ |
| 242 |
Tk_Window tkwin; /* Not used. */ |
| 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 |
* BusyGeometryProc -- |
| 257 |
* |
| 258 |
* This procedure is invoked by Tk_GeometryRequest for busy |
| 259 |
* windows. Busy windows never request geometry, so it's |
| 260 |
* unlikely that this routine will ever be called. The routine |
| 261 |
* exists simply as a place holder for the GeomProc in the |
| 262 |
* Geometry Manager structure. |
| 263 |
* |
| 264 |
* Results: |
| 265 |
* None. |
| 266 |
* |
| 267 |
* ---------------------------------------------------------------------------- |
| 268 |
*/ |
| 269 |
/* ARGSUSED */ |
| 270 |
static void |
| 271 |
BusyGeometryProc(clientData, tkwin) |
| 272 |
ClientData clientData; /* Information about window that got new |
| 273 |
* preferred geometry. */ |
| 274 |
Tk_Window tkwin; /* Other Tk-related information about the |
| 275 |
* window. */ |
| 276 |
{ |
| 277 |
/* Should never get here */ |
| 278 |
} |
| 279 |
|
| 280 |
/* |
| 281 |
* ------------------------------------------------------------------ |
| 282 |
* |
| 283 |
* RefWinEventProc -- |
| 284 |
* |
| 285 |
* This procedure is invoked by the Tk dispatcher for the |
| 286 |
* following events on the reference window. If the reference and |
| 287 |
* parent windows are the same, only the first event is |
| 288 |
* important. |
| 289 |
* |
| 290 |
* 1) ConfigureNotify - The reference window has been resized or |
| 291 |
* moved. Move and resize the busy window |
| 292 |
* to be the same size and position of the |
| 293 |
* reference window. |
| 294 |
* |
| 295 |
* 2) DestroyNotify - The reference window was destroyed. Destroy |
| 296 |
* the busy window and the free resources |
| 297 |
* used. |
| 298 |
* |
| 299 |
* 3) MapNotify - The reference window was (re)shown. Map the |
| 300 |
* busy window again. |
| 301 |
* |
| 302 |
* 4) UnmapNotify - The reference window was hidden. Unmap the |
| 303 |
* busy window. |
| 304 |
* |
| 305 |
* Results: |
| 306 |
* None. |
| 307 |
* |
| 308 |
* Side effects: |
| 309 |
* When the reference window gets deleted, internal structures get |
| 310 |
* cleaned up. When it gets resized, the busy window is resized |
| 311 |
* accordingly. If it's displayed, the busy window is displayed. And |
| 312 |
* when it's hidden, the busy window is unmapped. |
| 313 |
* |
| 314 |
* ------------------------------------------------------------------- |
| 315 |
*/ |
| 316 |
static void |
| 317 |
RefWinEventProc(clientData, eventPtr) |
| 318 |
ClientData clientData; /* Busy window record */ |
| 319 |
register XEvent *eventPtr; /* Event which triggered call to routine */ |
| 320 |
{ |
| 321 |
register Busy *busyPtr = clientData; |
| 322 |
|
| 323 |
switch (eventPtr->type) { |
| 324 |
case ReparentNotify: |
| 325 |
case DestroyNotify: |
| 326 |
|
| 327 |
/* |
| 328 |
* Arrange for the busy structure to be removed at a proper time. |
| 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 |
* ConfigureBusy -- |
| 397 |
* |
| 398 |
* This procedure is called from the Tk event dispatcher. It |
| 399 |
* releases X resources and memory used by the busy window and |
| 400 |
* updates the internal hash table. |
| 401 |
* |
| 402 |
* Results: |
| 403 |
* None. |
| 404 |
* |
| 405 |
* Side effects: |
| 406 |
* Memory and resources are released and the Tk event handler |
| 407 |
* is removed. |
| 408 |
* |
| 409 |
* ------------------------------------------------------------------- |
| 410 |
*/ |
| 411 |
static int |
| 412 |
ConfigureBusy(interp, busyPtr, argc, argv) |
| 413 |
Tcl_Interp *interp; |
| 414 |
Busy *busyPtr; |
| 415 |
int argc; |
| 416 |
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 |
* CreateBusy -- |
| 439 |
* |
| 440 |
* Creates a child transparent window that obscures its parent |
| 441 |
* window thereby effectively blocking device events. The size |
| 442 |
* and position of the busy window is exactly that of the reference |
| 443 |
* window. |
| 444 |
* |
| 445 |
* We want to create sibling to the window to be blocked. If the |
| 446 |
* busy window is a child of the window to be blocked, Enter/Leave |
| 447 |
* events can sneak through. Futhermore under WIN32, messages of |
| 448 |
* transparent windows are sent directly to the parent. The only |
| 449 |
* exception to this are toplevels, since we can't make a sibling. |
| 450 |
* Fortunately, toplevel windows rarely receive events that need |
| 451 |
* blocking. |
| 452 |
* |
| 453 |
* Results: |
| 454 |
* Returns a pointer to the new busy window structure. |
| 455 |
* |
| 456 |
* Side effects: |
| 457 |
* When the busy window is eventually displayed, it will screen |
| 458 |
* device events (in the area of the reference window) from reaching |
| 459 |
* its parent window and its children. User feed back can be |
| 460 |
* achieved by changing the cursor. |
| 461 |
* |
| 462 |
* ------------------------------------------------------------------- |
| 463 |
*/ |
| 464 |
static Busy * |
| 465 |
CreateBusy(interp, tkRef) |
| 466 |
Tcl_Interp *interp; /* Interpreter to report error to */ |
| 467 |
Tk_Window tkRef; /* Window hosting the busy window */ |
| 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"; /* Child */ |
| 485 |
tkParent = tkRef; |
| 486 |
} else { |
| 487 |
Tk_Window tkwin; |
| 488 |
|
| 489 |
fmt = "%s_Busy"; /* Sibling */ |
| 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 |
* This works around a bug in the implementation of menubars |
| 531 |
* for non-MacIntosh window systems (Win32 and X11). Tk |
| 532 |
* doesn't reset the pointers to the parent window when the |
| 533 |
* menu is reparented (winPtr->parentPtr points to the |
| 534 |
* wrong window). We get around this by determining the parent |
| 535 |
* via the native API calls. |
| 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 |
/* Only worry if the busy window is destroyed. */ |
| 573 |
Tk_CreateEventHandler(tkBusy, StructureNotifyMask, BusyEventProc, busyPtr); |
| 574 |
/* |
| 575 |
* Indicate that the busy window's geometry is being managed. |
| 576 |
* This will also notify us if the busy window is ever packed. |
| 577 |
*/ |
| 578 |
Tk_ManageGeometry(tkBusy, &busyMgrInfo, busyPtr); |
| 579 |
if (busyPtr->cursor != None) { |
| 580 |
Tk_DefineCursor(tkBusy, busyPtr->cursor); |
| 581 |
} |
| 582 |
/* Track the reference window to see if it is resized or destroyed. */ |
| 583 |
Tk_CreateEventHandler(tkRef, StructureNotifyMask, RefWinEventProc, busyPtr); |
| 584 |
return busyPtr; |
| 585 |
} |
| 586 |
|
| 587 |
/* |
| 588 |
* ------------------------------------------------------------------ |
| 589 |
* |
| 590 |
* DestroyBusy -- |
| 591 |
* |
| 592 |
* This procedure is called from the Tk event dispatcher. It |
| 593 |
* releases X resources and memory used by the busy window and |
| 594 |
* updates the internal hash table. |
| 595 |
* |
| 596 |
* Results: |
| 597 |
* None. |
| 598 |
* |
| 599 |
* Side effects: |
| 600 |
* Memory and resources are released and the Tk event handler |
| 601 |
* is removed. |
| 602 |
* |
| 603 |
* ------------------------------------------------------------------- |
| 604 |
*/ |
| 605 |
static void |
| 606 |
DestroyBusy(data) |
| 607 |
DestroyData data; /* Busy window structure record */ |
| 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 |
* GetBusy -- |
| 630 |
* |
| 631 |
* Returns the busy window structure associated with the reference |
| 632 |
* window, keyed by its path name. The clientData argument is |
| 633 |
* the main window of the interpreter, used to search for the |
| 634 |
* reference window in its own window hierarchy. |
| 635 |
* |
| 636 |
* Results: |
| 637 |
* If path name represents a reference window with a busy window, a |
| 638 |
* pointer to the busy window structure is returned. Otherwise, |
| 639 |
* NULL is returned and an error message is left in |
| 640 |
* interp->result. |
| 641 |
* |
| 642 |
* ------------------------------------------------------------------- |
| 643 |
*/ |
| 644 |
static int |
| 645 |
GetBusy(dataPtr, interp, pathName, busyPtrPtr) |
| 646 |
BusyInterpData *dataPtr; /* Interpreter-specific data. */ |
| 647 |
Tcl_Interp *interp; /* Interpreter to report errors to */ |
| 648 |
char *pathName; /* Path name of parent window */ |
| 649 |
Busy **busyPtrPtr; /* Will contain address of busy window if |
| 650 |
* found. */ |
| 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 |
* HoldBusy -- |
| 673 |
* |
| 674 |
* Creates (if necessary) and maps a busy window, thereby |
| 675 |
* preventing device events from being be received by the parent |
| 676 |
* window and its children. |
| 677 |
* |
| 678 |
* Results: |
| 679 |
* Returns a standard TCL result. If path name represents a busy |
| 680 |
* window, it is unmapped and TCL_OK is returned. Otherwise, |
| 681 |
* TCL_ERROR is returned and an error message is left in |
| 682 |
* interp->result. |
| 683 |
* |
| 684 |
* Side effects: |
| 685 |
* The busy window is created and displayed, blocking events from |
| 686 |
* the parent window and its children. |
| 687 |
* |
| 688 |
* ------------------------------------------------------------------- |
| 689 |
*/ |
| 690 |
static int |
| 691 |
HoldBusy(dataPtr, interp, argc, argv) |
| 692 |
BusyInterpData *dataPtr; /* Interpreter-specific data. */ |
| 693 |
Tcl_Interp *interp; /* Interpreter to report errors to */ |
| 694 |
int argc; |
| 695 |
char **argv; /* Window name and option pairs */ |
| 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 |
* Don't map the busy window unless the reference window is also |
| 723 |
* currently displayed. |
| 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 |
* StatusOp -- |
| 738 |
* |
| 739 |
* Returns the status of the busy window; whether it's blocking |
| 740 |
* events or not. |
| 741 |
* |
| 742 |
* Results: |
| 743 |
* Returns a standard TCL result. If path name represents a busy |
| 744 |
* window, the status is returned via interp->result and TCL_OK |
| 745 |
* is returned. Otherwise, TCL_ERROR is returned and an error |
| 746 |
* message is left in interp->result. |
| 747 |
* |
| 748 |
* ------------------------------------------------------------------- |
| 749 |
*/ |
| 750 |
/*ARGSUSED*/ |
| 751 |
static int |
| 752 |
StatusOp(clientData, interp, argc, argv) |
| 753 |
ClientData clientData; /* Interpreter-specific data. */ |
| 754 |
Tcl_Interp *interp; /* Interpreter to report error to */ |
| 755 |
int argc; /* Not used. */ |
| 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 |
* ForgetOp -- |
| 774 |
* |
| 775 |
* Destroys the busy window associated with the reference window and |
| 776 |
* arranges for internal resources to the released when they're |
| 777 |
* not being used anymore. |
| 778 |
* |
| 779 |
* Results: |
| 780 |
* Returns a standard TCL result. If path name represents a busy |
| 781 |
* window, it is destroyed and TCL_OK is returned. Otherwise, |
| 782 |
* TCL_ERROR is returned and an error message is left in |
| 783 |
* interp->result. |
| 784 |
* |
| 785 |
* Side effects: |
| 786 |
* The busy window is removed. Other related memory and resources |
| 787 |
* are eventually released by the Tk dispatcher. |
| 788 |
* |
| 789 |
* ------------------------------------------------------------------- |
| 790 |
*/ |
| 791 |
static int |
| 792 |
ForgetOp(clientData, interp, argc, argv) |
| 793 |
ClientData clientData; /* Interpreter-specific data. */ |
| 794 |
Tcl_Interp *interp; /* Interpreter to report errors to */ |
| 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 |
/* Unmap the window even though it will be soon destroyed */ |
| 807 |
HideBusyWindow(busyPtr); |
| 808 |
Tcl_EventuallyFree(busyPtr, DestroyBusy); |
| 809 |
} |
| 810 |
return TCL_OK; |
| 811 |
} |
| 812 |
|
| 813 |
/* |
| 814 |
* ------------------------------------------------------------------ |
| 815 |
* |
| 816 |
* ReleaseOp -- |
| 817 |
* |
| 818 |
* Unmaps the busy window, thereby permitting device events |
| 819 |
* to be received by the parent window and its children. |
| 820 |
* |
| 821 |
* Results: |
| 822 |
* Returns a standard TCL result. If path name represents a busy |
| 823 |
* window, it is unmapped and TCL_OK is returned. Otherwise, |
| 824 |
* TCL_ERROR is returned and an error message is left in |
| 825 |
* interp->result. |
| 826 |
* |
| 827 |
* Side effects: |
| 828 |
* The busy window is hidden, allowing the parent window and |
| 829 |
* its children to receive events again. |
| 830 |
* |
| 831 |
* ------------------------------------------------------------------- |
| 832 |
*/ |
| 833 |
static int |
| 834 |
ReleaseOp(clientData, interp, argc, argv) |
| 835 |
ClientData clientData; /* Interpreter-specific data. */ |
| 836 |
Tcl_Interp *interp; /* Interpreter to report errors to */ |
| 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 |
* NamesOp -- |
| 858 |
* |
| 859 |
* Reports the names of all widgets with busy windows attached to |
| 860 |
* them, matching a given pattern. If no pattern is given, all |
| 861 |
* busy widgets are listed. |
| 862 |
* |
| 863 |
* Results: |
| 864 |
* Returns a TCL list of the names of the widget with busy windows |
| 865 |
* attached to them, regardless if the widget is currently busy |
| 866 |
* or not. |
| 867 |
* |
| 868 |
* ------------------------------------------------------------------- |
| 869 |
*/ |
| 870 |
static int |
| 871 |
NamesOp(clientData, interp, argc, argv) |
| 872 |
ClientData clientData; /* Interpreter-specific data. */ |
| 873 |
Tcl_Interp *interp; /* Interpreter to report errors to */ |
| 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 |
* BusyOp -- |
| 897 |
* |
| 898 |
* Reports the names of all widgets with busy windows attached to |
| 899 |
* them, matching a given pattern. If no pattern is given, all |
| 900 |
* busy widgets are listed. |
| 901 |
* |
| 902 |
* Results: |
| 903 |
* Returns a TCL list of the names of the widget with busy windows |
| 904 |
* attached to them, regardless if the widget is currently busy |
| 905 |
* or not. |
| 906 |
* |
| 907 |
* ------------------------------------------------------------------- |
| 908 |
*/ |
| 909 |
static int |
| 910 |
BusyOp(clientData, interp, argc, argv) |
| 911 |
ClientData clientData; /* Interpreter-specific data. */ |
| 912 |
Tcl_Interp *interp; /* Interpreter to report errors to */ |
| 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 |
* HoldOp -- |
| 939 |
* |
| 940 |
* Creates (if necessary) and maps a busy window, thereby |
| 941 |
* preventing device events from being be received by the parent |
| 942 |
* window and its children. The argument vector may contain |
| 943 |
* option-value pairs of configuration options to be set. |
| 944 |
* |
| 945 |
* Results: |
| 946 |
* Returns a standard TCL result. |
| 947 |
* |
| 948 |
* Side effects: |
| 949 |
* The busy window is created and displayed, blocking events from the |
| 950 |
* parent window and its children. |
| 951 |
* |
| 952 |
* ------------------------------------------------------------------- |
| 953 |
*/ |
| 954 |
static int |
| 955 |
HoldOp(clientData, interp, argc, argv) |
| 956 |
ClientData clientData; /* Interpreter-specific data. */ |
| 957 |
Tcl_Interp *interp; /* Interpreter to report errors to */ |
| 958 |
int argc; |
| 959 |
char **argv; /* Window name and option pairs */ |
| 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++; /* Command used "hold" keyword */ |
| 966 |
} |
| 967 |
for (i = 1; i < argc; i++) { |
| 968 |
/* |
| 969 |
* Find the end of the option-value pairs for this window. |
| 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 |
/* ARGSUSED*/ |
| 988 |
static int |
| 989 |
CgetOp(clientData, interp, argc, argv) |
| 990 |
ClientData clientData; /* Interpreter-specific data. */ |
| 991 |
Tcl_Interp *interp; /* Interpreter to report errors to */ |
| 992 |
int argc; |
| 993 |
char **argv; /* Widget pathname and option switch */ |
| 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 |
* ConfigureOp -- |
| 1013 |
* |
| 1014 |
* This procedure is called to process an argv/argc list in order |
| 1015 |
* to configure (or reconfigure) a busy window. |
| 1016 |
* |
| 1017 |
* Results: |
| 1018 |
* The return value is a standard Tcl result. If TCL_ERROR is |
| 1019 |
* returned, then interp->result contains an error message. |
| 1020 |
* |
| 1021 |
* Side effects: |
| 1022 |
* Configuration information get set for busyPtr; old resources |
| 1023 |
* get freed, if there were any. The busy window destroyed and |
| 1024 |
* recreated in a new parent window. |
| 1025 |
* |
| 1026 |
*---------------------------------------------------------------------- |
| 1027 |
*/ |
| 1028 |
static int |
| 1029 |
ConfigureOp(clientData, interp, argc, argv) |
| 1030 |
ClientData clientData; /* Interpreter-specific data. */ |
| 1031 |
Tcl_Interp *interp; /* Interpreter to report errors to */ |
| 1032 |
int argc; |
| 1033 |
char **argv; /* Reference window path name and options */ |
| 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 |
* BusyInterpDeleteProc -- |
| 1060 |
* |
| 1061 |
* This is called when the interpreter hosting the "busy" command |
| 1062 |
* is destroyed. |
| 1063 |
* |
| 1064 |
* Results: |
| 1065 |
* None. |
| 1066 |
* |
| 1067 |
* Side effects: |
| 1068 |
* Destroys all the hash table managing the busy windows. |
| 1069 |
* |
| 1070 |
* ------------------------------------------------------------------------ |
| 1071 |
*/ |
| 1072 |
/* ARGSUSED */ |
| 1073 |
static void |
| 1074 |
BusyInterpDeleteProc(clientData, interp) |
| 1075 |
ClientData clientData; /* Interpreter-specific data. */ |
| 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 |
* Busy Sub-command specification: |
| 1098 |
* |
| 1099 |
* - Name of the sub-command. |
| 1100 |
* - Minimum number of characters needed to unambiguously |
| 1101 |
* recognize the sub-command. |
| 1102 |
* - Pointer to the function to be called for the sub-command. |
| 1103 |
* - Minimum number of arguments accepted. |
| 1104 |
* - Maximum number of arguments accepted. |
| 1105 |
* - String to be displayed for usage (arguments only). |
| 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 |
* BusyCmd -- |
| 1128 |
* |
| 1129 |
* This procedure is invoked to process the "busy" Tcl command. |
| 1130 |
* See the user documentation for details on what it does. |
| 1131 |
* |
| 1132 |
* Results: |
| 1133 |
* A standard Tcl result. |
| 1134 |
* |
| 1135 |
* Side effects: |
| 1136 |
* See the user documentation. |
| 1137 |
* |
| 1138 |
*---------------------------------------------------------------------- |
| 1139 |
*/ |
| 1140 |
static int |
| 1141 |
BusyCmd(clientData, interp, argc, argv) |
| 1142 |
ClientData clientData; /* Interpreter-specific data. */ |
| 1143 |
Tcl_Interp *interp; /* Interpreter associated with command */ |
| 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 /* NO_BUSY */ |