| 1 |
/* |
| 2 |
* tkWinWindow.c -- |
| 3 |
* |
| 4 |
* Xlib emulation routines for Windows related to creating, |
| 5 |
* displaying and destroying windows. |
| 6 |
* |
| 7 |
* Copyright (c) 1995-1997 Sun Microsystems, Inc. |
| 8 |
* |
| 9 |
* See the file "license.terms" for information on usage and redistribution |
| 10 |
* of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 11 |
* |
| 12 |
* RCS: @(#) $Id: tkWinWindow.c,v 1.10 2002/06/14 22:25:12 jenglish Exp $ |
| 13 |
*/ |
| 14 |
|
| 15 |
#include "tkWinInt.h" |
| 16 |
|
| 17 |
typedef struct ThreadSpecificData { |
| 18 |
int initialized; /* 0 means table below needs initializing. */ |
| 19 |
Tcl_HashTable windowTable; /* The windowTable maps from HWND to |
| 20 |
* Tk_Window handles. */ |
| 21 |
} ThreadSpecificData; |
| 22 |
static Tcl_ThreadDataKey dataKey; |
| 23 |
|
| 24 |
/* |
| 25 |
* Forward declarations for procedures defined in this file: |
| 26 |
*/ |
| 27 |
|
| 28 |
static void NotifyVisibility _ANSI_ARGS_((XEvent *eventPtr, |
| 29 |
TkWindow *winPtr)); |
| 30 |
|
| 31 |
/* |
| 32 |
*---------------------------------------------------------------------- |
| 33 |
* |
| 34 |
* Tk_AttachHWND -- |
| 35 |
* |
| 36 |
* This function binds an HWND and a reflection procedure to |
| 37 |
* the specified Tk_Window. |
| 38 |
* |
| 39 |
* Results: |
| 40 |
* Returns an X Window that encapsulates the HWND. |
| 41 |
* |
| 42 |
* Side effects: |
| 43 |
* May allocate a new X Window. Also enters the HWND into the |
| 44 |
* global window table. |
| 45 |
* |
| 46 |
*---------------------------------------------------------------------- |
| 47 |
*/ |
| 48 |
|
| 49 |
Window |
| 50 |
Tk_AttachHWND(tkwin, hwnd) |
| 51 |
Tk_Window tkwin; |
| 52 |
HWND hwnd; |
| 53 |
{ |
| 54 |
int new; |
| 55 |
Tcl_HashEntry *entryPtr; |
| 56 |
TkWinDrawable *twdPtr = (TkWinDrawable *) Tk_WindowId(tkwin); |
| 57 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 58 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 59 |
|
| 60 |
if (!tsdPtr->initialized) { |
| 61 |
Tcl_InitHashTable(&tsdPtr->windowTable, TCL_ONE_WORD_KEYS); |
| 62 |
tsdPtr->initialized = 1; |
| 63 |
} |
| 64 |
|
| 65 |
/* |
| 66 |
* Allocate a new drawable if necessary. Otherwise, remove the |
| 67 |
* previous HWND from from the window table. |
| 68 |
*/ |
| 69 |
|
| 70 |
if (twdPtr == NULL) { |
| 71 |
twdPtr = (TkWinDrawable*) ckalloc(sizeof(TkWinDrawable)); |
| 72 |
twdPtr->type = TWD_WINDOW; |
| 73 |
twdPtr->window.winPtr = (TkWindow *) tkwin; |
| 74 |
} else if (twdPtr->window.handle != NULL) { |
| 75 |
entryPtr = Tcl_FindHashEntry(&tsdPtr->windowTable, |
| 76 |
(char *)twdPtr->window.handle); |
| 77 |
Tcl_DeleteHashEntry(entryPtr); |
| 78 |
} |
| 79 |
|
| 80 |
/* |
| 81 |
* Insert the new HWND into the window table. |
| 82 |
*/ |
| 83 |
|
| 84 |
twdPtr->window.handle = hwnd; |
| 85 |
entryPtr = Tcl_CreateHashEntry(&tsdPtr->windowTable, (char *)hwnd, &new); |
| 86 |
Tcl_SetHashValue(entryPtr, (ClientData)tkwin); |
| 87 |
|
| 88 |
|
| 89 |
return (Window)twdPtr; |
| 90 |
} |
| 91 |
|
| 92 |
/* |
| 93 |
*---------------------------------------------------------------------- |
| 94 |
* |
| 95 |
* Tk_HWNDToWindow -- |
| 96 |
* |
| 97 |
* This function retrieves a Tk_Window from the window table |
| 98 |
* given an HWND. |
| 99 |
* |
| 100 |
* Results: |
| 101 |
* Returns the matching Tk_Window. |
| 102 |
* |
| 103 |
* Side effects: |
| 104 |
* None. |
| 105 |
* |
| 106 |
*---------------------------------------------------------------------- |
| 107 |
*/ |
| 108 |
|
| 109 |
Tk_Window |
| 110 |
Tk_HWNDToWindow(hwnd) |
| 111 |
HWND hwnd; |
| 112 |
{ |
| 113 |
Tcl_HashEntry *entryPtr; |
| 114 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 115 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 116 |
|
| 117 |
if (!tsdPtr->initialized) { |
| 118 |
Tcl_InitHashTable(&tsdPtr->windowTable, TCL_ONE_WORD_KEYS); |
| 119 |
tsdPtr->initialized = 1; |
| 120 |
} |
| 121 |
entryPtr = Tcl_FindHashEntry(&tsdPtr->windowTable, (char*)hwnd); |
| 122 |
if (entryPtr != NULL) { |
| 123 |
return (Tk_Window) Tcl_GetHashValue(entryPtr); |
| 124 |
} |
| 125 |
return NULL; |
| 126 |
} |
| 127 |
|
| 128 |
/* |
| 129 |
*---------------------------------------------------------------------- |
| 130 |
* |
| 131 |
* Tk_GetHWND -- |
| 132 |
* |
| 133 |
* This function extracts the HWND from an X Window. |
| 134 |
* |
| 135 |
* Results: |
| 136 |
* Returns the HWND associated with the Window. |
| 137 |
* |
| 138 |
* Side effects: |
| 139 |
* None. |
| 140 |
* |
| 141 |
*---------------------------------------------------------------------- |
| 142 |
*/ |
| 143 |
|
| 144 |
HWND |
| 145 |
Tk_GetHWND(window) |
| 146 |
Window window; |
| 147 |
{ |
| 148 |
if (window != None) { |
| 149 |
TkWinDrawable *twdPtr = (TkWinDrawable *) window; |
| 150 |
return twdPtr->window.handle; |
| 151 |
} else { |
| 152 |
/* None is returned for Root Window */ |
| 153 |
return GetDesktopWindow(); |
| 154 |
} |
| 155 |
} |
| 156 |
|
| 157 |
/* |
| 158 |
*---------------------------------------------------------------------- |
| 159 |
* |
| 160 |
* TkpPrintWindowId -- |
| 161 |
* |
| 162 |
* This routine stores the string representation of the |
| 163 |
* platform dependent window handle for an X Window in the |
| 164 |
* given buffer. |
| 165 |
* |
| 166 |
* Results: |
| 167 |
* Returns the result in the specified buffer. |
| 168 |
* |
| 169 |
* Side effects: |
| 170 |
* None. |
| 171 |
* |
| 172 |
*---------------------------------------------------------------------- |
| 173 |
*/ |
| 174 |
|
| 175 |
void |
| 176 |
TkpPrintWindowId(buf, window) |
| 177 |
char *buf; /* Pointer to string large enough to hold |
| 178 |
* the hex representation of a pointer. */ |
| 179 |
Window window; /* Window to be printed into buffer. */ |
| 180 |
{ |
| 181 |
HWND hwnd = (window) ? Tk_GetHWND(window) : 0; |
| 182 |
/* |
| 183 |
* Use pointer representation, because Win64 is P64 (*not* LP64). |
| 184 |
* Windows doesn't print the 0x for %p, so we do it. |
| 185 |
*/ |
| 186 |
sprintf(buf, "0x%p", hwnd); |
| 187 |
} |
| 188 |
|
| 189 |
/* |
| 190 |
*---------------------------------------------------------------------- |
| 191 |
* |
| 192 |
* TkpScanWindowId -- |
| 193 |
* |
| 194 |
* Given a string which represents the platform dependent window |
| 195 |
* handle, produce the X Window id for the window. |
| 196 |
* |
| 197 |
* Results: |
| 198 |
* The return value is normally TCL_OK; in this case *idPtr |
| 199 |
* will be set to the X Window id equivalent to string. If |
| 200 |
* string is improperly formed then TCL_ERROR is returned and |
| 201 |
* an error message will be left in the interp's result. If the |
| 202 |
* number does not correspond to a Tk Window, then *idPtr will |
| 203 |
* be set to None. |
| 204 |
* |
| 205 |
* Side effects: |
| 206 |
* None. |
| 207 |
* |
| 208 |
*---------------------------------------------------------------------- |
| 209 |
*/ |
| 210 |
|
| 211 |
int |
| 212 |
TkpScanWindowId(interp, string, idPtr) |
| 213 |
Tcl_Interp *interp; /* Interpreter to use for error reporting. */ |
| 214 |
Tcl_Obj *string; /* String containing a (possibly signed) |
| 215 |
* integer in a form acceptable to strtol. */ |
| 216 |
Window *idPtr; /* Place to store converted result. */ |
| 217 |
{ |
| 218 |
Tk_Window tkwin; |
| 219 |
Window number; |
| 220 |
|
| 221 |
/* |
| 222 |
* We want sscanf for the 64-bit check, but if that doesn't work, |
| 223 |
* then Tcl_GetInt manages the error correctly. |
| 224 |
*/ |
| 225 |
if ( |
| 226 |
#ifdef _WIN64 |
| 227 |
(sscanf(string, "0x%p", &number) != 1) && |
| 228 |
#endif |
| 229 |
Tcl_GetIntFromObj(interp, string, (int *)&number) != TCL_OK) { |
| 230 |
return TCL_ERROR; |
| 231 |
} |
| 232 |
|
| 233 |
tkwin = Tk_HWNDToWindow((HWND)number); |
| 234 |
if (tkwin) { |
| 235 |
*idPtr = Tk_WindowId(tkwin); |
| 236 |
} else { |
| 237 |
*idPtr = None; |
| 238 |
} |
| 239 |
return TCL_OK; |
| 240 |
} |
| 241 |
|
| 242 |
/* |
| 243 |
*---------------------------------------------------------------------- |
| 244 |
* |
| 245 |
* TkpMakeWindow -- |
| 246 |
* |
| 247 |
* Creates a Windows window object based on the current attributes |
| 248 |
* of the specified TkWindow. |
| 249 |
* |
| 250 |
* Results: |
| 251 |
* Returns a pointer to a new TkWinDrawable cast to a Window. |
| 252 |
* |
| 253 |
* Side effects: |
| 254 |
* Creates a new window. |
| 255 |
* |
| 256 |
*---------------------------------------------------------------------- |
| 257 |
*/ |
| 258 |
|
| 259 |
Window |
| 260 |
TkpMakeWindow(winPtr, parent) |
| 261 |
TkWindow *winPtr; |
| 262 |
Window parent; |
| 263 |
{ |
| 264 |
HWND parentWin; |
| 265 |
int style; |
| 266 |
HWND hwnd; |
| 267 |
|
| 268 |
if (parent != None) { |
| 269 |
parentWin = Tk_GetHWND(parent); |
| 270 |
style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; |
| 271 |
} else { |
| 272 |
#ifdef __OPEN32__ |
| 273 |
/* Open32 treats topmost windows specially, so we keep any |
| 274 |
window as not a toplevel. */ |
| 275 |
if (tmpParent == NULL) { |
| 276 |
tmpParent = CreateWindow(TK_WIN_CHILD_CLASS_NAME, "", WS_POPUP, |
| 277 |
0, 0, |
| 278 |
0, 0, |
| 279 |
NULL, NULL, TkWinGetAppInstance(), NULL); |
| 280 |
ShowWindow(tmpParent, SW_HIDE); |
| 281 |
} |
| 282 |
parentWin = tmpParent; |
| 283 |
style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; |
| 284 |
#else |
| 285 |
parentWin = NULL; |
| 286 |
style = WS_POPUP | WS_CLIPCHILDREN; |
| 287 |
#endif |
| 288 |
} |
| 289 |
|
| 290 |
/* |
| 291 |
* Create the window, then ensure that it is at the top of the |
| 292 |
* stacking order. |
| 293 |
*/ |
| 294 |
|
| 295 |
hwnd = CreateWindowEx(WS_EX_NOPARENTNOTIFY, TK_WIN_CHILD_CLASS_NAME, NULL, |
| 296 |
style, Tk_X(winPtr), Tk_Y(winPtr), Tk_Width(winPtr), |
| 297 |
Tk_Height(winPtr), parentWin, NULL, Tk_GetHINSTANCE(), NULL); |
| 298 |
SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, |
| 299 |
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); |
| 300 |
return Tk_AttachHWND((Tk_Window)winPtr, hwnd); |
| 301 |
} |
| 302 |
|
| 303 |
/* |
| 304 |
*---------------------------------------------------------------------- |
| 305 |
* |
| 306 |
* XDestroyWindow -- |
| 307 |
* |
| 308 |
* Destroys the given window. |
| 309 |
* |
| 310 |
* Results: |
| 311 |
* None. |
| 312 |
* |
| 313 |
* Side effects: |
| 314 |
* Sends the WM_DESTROY message to the window and then destroys |
| 315 |
* it the Win32 resources associated with the window. |
| 316 |
* |
| 317 |
*---------------------------------------------------------------------- |
| 318 |
*/ |
| 319 |
|
| 320 |
void |
| 321 |
XDestroyWindow(display, w) |
| 322 |
Display* display; |
| 323 |
Window w; |
| 324 |
{ |
| 325 |
Tcl_HashEntry *entryPtr; |
| 326 |
TkWinDrawable *twdPtr = (TkWinDrawable *)w; |
| 327 |
TkWindow *winPtr = TkWinGetWinPtr(w); |
| 328 |
HWND hwnd = Tk_GetHWND(w); |
| 329 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 330 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 331 |
|
| 332 |
display->request++; |
| 333 |
|
| 334 |
/* |
| 335 |
* Remove references to the window in the pointer module then |
| 336 |
* release the drawable. |
| 337 |
*/ |
| 338 |
|
| 339 |
TkPointerDeadWindow(winPtr); |
| 340 |
|
| 341 |
entryPtr = Tcl_FindHashEntry(&tsdPtr->windowTable, (char*)hwnd); |
| 342 |
if (entryPtr != NULL) { |
| 343 |
Tcl_DeleteHashEntry(entryPtr); |
| 344 |
} |
| 345 |
|
| 346 |
ckfree((char *)twdPtr); |
| 347 |
|
| 348 |
/* |
| 349 |
* Don't bother destroying the window if we are going to destroy |
| 350 |
* the parent later. |
| 351 |
*/ |
| 352 |
|
| 353 |
if (hwnd != NULL && !(winPtr->flags & TK_DONT_DESTROY_WINDOW)) { |
| 354 |
DestroyWindow(hwnd); |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
/* |
| 359 |
*---------------------------------------------------------------------- |
| 360 |
* |
| 361 |
* XMapWindow -- |
| 362 |
* |
| 363 |
* Cause the given window to become visible. |
| 364 |
* |
| 365 |
* Results: |
| 366 |
* None |
| 367 |
* |
| 368 |
* Side effects: |
| 369 |
* Causes the window state to change, and generates a MapNotify |
| 370 |
* event. |
| 371 |
* |
| 372 |
*---------------------------------------------------------------------- |
| 373 |
*/ |
| 374 |
|
| 375 |
void |
| 376 |
XMapWindow(display, w) |
| 377 |
Display* display; |
| 378 |
Window w; |
| 379 |
{ |
| 380 |
XEvent event; |
| 381 |
TkWindow *parentPtr; |
| 382 |
TkWindow *winPtr = TkWinGetWinPtr(w); |
| 383 |
|
| 384 |
display->request++; |
| 385 |
|
| 386 |
ShowWindow(Tk_GetHWND(w), SW_SHOWNORMAL); |
| 387 |
winPtr->flags |= TK_MAPPED; |
| 388 |
|
| 389 |
/* |
| 390 |
* Check to see if this window is visible now. If all of the parent |
| 391 |
* windows up to the first toplevel are mapped, then this window and |
| 392 |
* its mapped children have just become visible. |
| 393 |
*/ |
| 394 |
|
| 395 |
if (!(winPtr->flags & TK_TOP_HIERARCHY)) { |
| 396 |
for (parentPtr = winPtr->parentPtr; ; |
| 397 |
parentPtr = parentPtr->parentPtr) { |
| 398 |
if ((parentPtr == NULL) || !(parentPtr->flags & TK_MAPPED)) { |
| 399 |
return; |
| 400 |
} |
| 401 |
if (parentPtr->flags & TK_TOP_HIERARCHY) { |
| 402 |
break; |
| 403 |
} |
| 404 |
} |
| 405 |
} else { |
| 406 |
event.type = MapNotify; |
| 407 |
event.xmap.serial = display->request; |
| 408 |
event.xmap.send_event = False; |
| 409 |
event.xmap.display = display; |
| 410 |
event.xmap.event = winPtr->window; |
| 411 |
event.xmap.window = winPtr->window; |
| 412 |
event.xmap.override_redirect = winPtr->atts.override_redirect; |
| 413 |
Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); |
| 414 |
} |
| 415 |
|
| 416 |
/* |
| 417 |
* Generate VisibilityNotify events for this window and its mapped |
| 418 |
* children. |
| 419 |
*/ |
| 420 |
|
| 421 |
event.type = VisibilityNotify; |
| 422 |
event.xvisibility.serial = display->request; |
| 423 |
event.xvisibility.send_event = False; |
| 424 |
event.xvisibility.display = display; |
| 425 |
event.xvisibility.window = winPtr->window; |
| 426 |
event.xvisibility.state = VisibilityUnobscured; |
| 427 |
NotifyVisibility(&event, winPtr); |
| 428 |
} |
| 429 |
|
| 430 |
/* |
| 431 |
*---------------------------------------------------------------------- |
| 432 |
* |
| 433 |
* NotifyVisibility -- |
| 434 |
* |
| 435 |
* This function recursively notifies the mapped children of the |
| 436 |
* specified window of a change in visibility. Note that we don't |
| 437 |
* properly report the visibility state, since Windows does not |
| 438 |
* provide that info. The eventPtr argument must point to an event |
| 439 |
* that has been completely initialized except for the window slot. |
| 440 |
* |
| 441 |
* Results: |
| 442 |
* None. |
| 443 |
* |
| 444 |
* Side effects: |
| 445 |
* Generates lots of events. |
| 446 |
* |
| 447 |
*---------------------------------------------------------------------- |
| 448 |
*/ |
| 449 |
|
| 450 |
static void |
| 451 |
NotifyVisibility(eventPtr, winPtr) |
| 452 |
XEvent *eventPtr; /* Initialized VisibilityNotify event. */ |
| 453 |
TkWindow *winPtr; /* Window to notify. */ |
| 454 |
{ |
| 455 |
if (winPtr->atts.event_mask & VisibilityChangeMask) { |
| 456 |
eventPtr->xvisibility.window = winPtr->window; |
| 457 |
Tk_QueueWindowEvent(eventPtr, TCL_QUEUE_TAIL); |
| 458 |
} |
| 459 |
for (winPtr = winPtr->childList; winPtr != NULL; |
| 460 |
winPtr = winPtr->nextPtr) { |
| 461 |
if (winPtr->flags & TK_MAPPED) { |
| 462 |
NotifyVisibility(eventPtr, winPtr); |
| 463 |
} |
| 464 |
} |
| 465 |
} |
| 466 |
|
| 467 |
/* |
| 468 |
*---------------------------------------------------------------------- |
| 469 |
* |
| 470 |
* XUnmapWindow -- |
| 471 |
* |
| 472 |
* Cause the given window to become invisible. |
| 473 |
* |
| 474 |
* Results: |
| 475 |
* None |
| 476 |
* |
| 477 |
* Side effects: |
| 478 |
* Causes the window state to change, and generates an UnmapNotify |
| 479 |
* event. |
| 480 |
* |
| 481 |
*---------------------------------------------------------------------- |
| 482 |
*/ |
| 483 |
|
| 484 |
void |
| 485 |
XUnmapWindow(display, w) |
| 486 |
Display* display; |
| 487 |
Window w; |
| 488 |
{ |
| 489 |
XEvent event; |
| 490 |
TkWindow *winPtr = TkWinGetWinPtr(w); |
| 491 |
|
| 492 |
display->request++; |
| 493 |
|
| 494 |
/* |
| 495 |
* Bug fix: Don't short circuit this routine based on TK_MAPPED because |
| 496 |
* it will be cleared before XUnmapWindow is called. |
| 497 |
*/ |
| 498 |
|
| 499 |
ShowWindow(Tk_GetHWND(w), SW_HIDE); |
| 500 |
winPtr->flags &= ~TK_MAPPED; |
| 501 |
|
| 502 |
if (winPtr->flags & TK_WIN_MANAGED) { |
| 503 |
event.type = UnmapNotify; |
| 504 |
event.xunmap.serial = display->request; |
| 505 |
event.xunmap.send_event = False; |
| 506 |
event.xunmap.display = display; |
| 507 |
event.xunmap.event = winPtr->window; |
| 508 |
event.xunmap.window = winPtr->window; |
| 509 |
event.xunmap.from_configure = False; |
| 510 |
Tk_HandleEvent(&event); |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
/* |
| 515 |
*---------------------------------------------------------------------- |
| 516 |
* |
| 517 |
* XMoveResizeWindow -- |
| 518 |
* |
| 519 |
* Move and resize a window relative to its parent. |
| 520 |
* |
| 521 |
* Results: |
| 522 |
* None. |
| 523 |
* |
| 524 |
* Side effects: |
| 525 |
* Repositions and resizes the specified window. |
| 526 |
* |
| 527 |
*---------------------------------------------------------------------- |
| 528 |
*/ |
| 529 |
|
| 530 |
void |
| 531 |
XMoveResizeWindow(display, w, x, y, width, height) |
| 532 |
Display* display; |
| 533 |
Window w; |
| 534 |
int x; /* Position relative to parent. */ |
| 535 |
int y; |
| 536 |
unsigned int width; |
| 537 |
unsigned int height; |
| 538 |
{ |
| 539 |
display->request++; |
| 540 |
MoveWindow(Tk_GetHWND(w), x, y, width, height, TRUE); |
| 541 |
} |
| 542 |
|
| 543 |
/* |
| 544 |
*---------------------------------------------------------------------- |
| 545 |
* |
| 546 |
* XMoveWindow -- |
| 547 |
* |
| 548 |
* Move a window relative to its parent. |
| 549 |
* |
| 550 |
* Results: |
| 551 |
* None. |
| 552 |
* |
| 553 |
* Side effects: |
| 554 |
* Repositions the specified window. |
| 555 |
* |
| 556 |
*---------------------------------------------------------------------- |
| 557 |
*/ |
| 558 |
|
| 559 |
void |
| 560 |
XMoveWindow(display, w, x, y) |
| 561 |
Display* display; |
| 562 |
Window w; |
| 563 |
int x; |
| 564 |
int y; |
| 565 |
{ |
| 566 |
TkWindow *winPtr = TkWinGetWinPtr(w); |
| 567 |
|
| 568 |
display->request++; |
| 569 |
|
| 570 |
MoveWindow(Tk_GetHWND(w), x, y, winPtr->changes.width, |
| 571 |
winPtr->changes.height, TRUE); |
| 572 |
} |
| 573 |
|
| 574 |
/* |
| 575 |
*---------------------------------------------------------------------- |
| 576 |
* |
| 577 |
* XResizeWindow -- |
| 578 |
* |
| 579 |
* Resize a window. |
| 580 |
* |
| 581 |
* Results: |
| 582 |
* None. |
| 583 |
* |
| 584 |
* Side effects: |
| 585 |
* Resizes the specified window. |
| 586 |
* |
| 587 |
*---------------------------------------------------------------------- |
| 588 |
*/ |
| 589 |
|
| 590 |
void |
| 591 |
XResizeWindow(display, w, width, height) |
| 592 |
Display* display; |
| 593 |
Window w; |
| 594 |
unsigned int width; |
| 595 |
unsigned int height; |
| 596 |
{ |
| 597 |
TkWindow *winPtr = TkWinGetWinPtr(w); |
| 598 |
|
| 599 |
display->request++; |
| 600 |
|
| 601 |
MoveWindow(Tk_GetHWND(w), winPtr->changes.x, winPtr->changes.y, width, |
| 602 |
height, TRUE); |
| 603 |
} |
| 604 |
|
| 605 |
/* |
| 606 |
*---------------------------------------------------------------------- |
| 607 |
* |
| 608 |
* XRaiseWindow -- |
| 609 |
* |
| 610 |
* Change the stacking order of a window. |
| 611 |
* |
| 612 |
* Results: |
| 613 |
* None. |
| 614 |
* |
| 615 |
* Side effects: |
| 616 |
* Changes the stacking order of the specified window. |
| 617 |
* |
| 618 |
*---------------------------------------------------------------------- |
| 619 |
*/ |
| 620 |
|
| 621 |
void |
| 622 |
XRaiseWindow(display, w) |
| 623 |
Display* display; |
| 624 |
Window w; |
| 625 |
{ |
| 626 |
HWND window = Tk_GetHWND(w); |
| 627 |
TkWinSetWindowPos(window, NULL, Above); |
| 628 |
} |
| 629 |
|
| 630 |
/* |
| 631 |
*---------------------------------------------------------------------- |
| 632 |
* |
| 633 |
* XLowerWindow -- |
| 634 |
* |
| 635 |
* Change the stacking order of a window. |
| 636 |
* |
| 637 |
* Results: |
| 638 |
* None. |
| 639 |
* |
| 640 |
* Side effects: |
| 641 |
* Changes the stacking order of the specified window. |
| 642 |
* |
| 643 |
*---------------------------------------------------------------------- |
| 644 |
*/ |
| 645 |
void |
| 646 |
XLowerWindow(display, w) |
| 647 |
Display* display; |
| 648 |
Window w; |
| 649 |
{ |
| 650 |
HWND window = Tk_GetHWND(w); |
| 651 |
TkWinSetWindowPos(window, NULL, Below); |
| 652 |
} |
| 653 |
|
| 654 |
/* |
| 655 |
*---------------------------------------------------------------------- |
| 656 |
* |
| 657 |
* XConfigureWindow -- |
| 658 |
* |
| 659 |
* Change the size, position, stacking, or border of the specified |
| 660 |
* window. |
| 661 |
* |
| 662 |
* Results: |
| 663 |
* None. |
| 664 |
* |
| 665 |
* Side effects: |
| 666 |
* Changes the attributes of the specified window. Note that we |
| 667 |
* ignore the passed in values and use the values stored in the |
| 668 |
* TkWindow data structure. |
| 669 |
* |
| 670 |
*---------------------------------------------------------------------- |
| 671 |
*/ |
| 672 |
|
| 673 |
void |
| 674 |
XConfigureWindow(display, w, value_mask, values) |
| 675 |
Display* display; |
| 676 |
Window w; |
| 677 |
unsigned int value_mask; |
| 678 |
XWindowChanges* values; |
| 679 |
{ |
| 680 |
TkWindow *winPtr = TkWinGetWinPtr(w); |
| 681 |
HWND hwnd = Tk_GetHWND(w); |
| 682 |
|
| 683 |
display->request++; |
| 684 |
|
| 685 |
/* |
| 686 |
* Change the shape and/or position of the window. |
| 687 |
*/ |
| 688 |
|
| 689 |
if (value_mask & (CWX|CWY|CWWidth|CWHeight)) { |
| 690 |
MoveWindow(hwnd, winPtr->changes.x, winPtr->changes.y, |
| 691 |
winPtr->changes.width, winPtr->changes.height, TRUE); |
| 692 |
} |
| 693 |
|
| 694 |
/* |
| 695 |
* Change the stacking order of the window. |
| 696 |
*/ |
| 697 |
|
| 698 |
if (value_mask & CWStackMode) { |
| 699 |
HWND sibling; |
| 700 |
if ((value_mask & CWSibling) && (values->sibling != None)) { |
| 701 |
sibling = Tk_GetHWND(values->sibling); |
| 702 |
} else { |
| 703 |
sibling = NULL; |
| 704 |
} |
| 705 |
TkWinSetWindowPos(hwnd, sibling, values->stack_mode); |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
/* |
| 710 |
*---------------------------------------------------------------------- |
| 711 |
* |
| 712 |
* XClearWindow -- |
| 713 |
* |
| 714 |
* Clears the entire window to the current background color. |
| 715 |
* |
| 716 |
* Results: |
| 717 |
* None. |
| 718 |
* |
| 719 |
* Side effects: |
| 720 |
* Erases the current contents of the window. |
| 721 |
* |
| 722 |
*---------------------------------------------------------------------- |
| 723 |
*/ |
| 724 |
|
| 725 |
void |
| 726 |
XClearWindow(display, w) |
| 727 |
Display* display; |
| 728 |
Window w; |
| 729 |
{ |
| 730 |
RECT rc; |
| 731 |
HBRUSH brush; |
| 732 |
HPALETTE oldPalette, palette; |
| 733 |
TkWindow *winPtr; |
| 734 |
HWND hwnd = Tk_GetHWND(w); |
| 735 |
HDC dc = GetDC(hwnd); |
| 736 |
|
| 737 |
palette = TkWinGetPalette(display->screens[0].cmap); |
| 738 |
oldPalette = SelectPalette(dc, palette, FALSE); |
| 739 |
|
| 740 |
display->request++; |
| 741 |
|
| 742 |
winPtr = TkWinGetWinPtr(w); |
| 743 |
brush = CreateSolidBrush(winPtr->atts.background_pixel); |
| 744 |
GetWindowRect(hwnd, &rc); |
| 745 |
rc.right = rc.right - rc.left; |
| 746 |
rc.bottom = rc.bottom - rc.top; |
| 747 |
rc.left = rc.top = 0; |
| 748 |
FillRect(dc, &rc, brush); |
| 749 |
|
| 750 |
DeleteObject(brush); |
| 751 |
SelectPalette(dc, oldPalette, TRUE); |
| 752 |
ReleaseDC(hwnd, dc); |
| 753 |
} |
| 754 |
|
| 755 |
/* |
| 756 |
*---------------------------------------------------------------------- |
| 757 |
* |
| 758 |
* XChangeWindowAttributes -- |
| 759 |
* |
| 760 |
* This function is called when the attributes on a window are |
| 761 |
* updated. Since Tk maintains all of the window state, the only |
| 762 |
* relevant value is the cursor. |
| 763 |
* |
| 764 |
* Results: |
| 765 |
* None. |
| 766 |
* |
| 767 |
* Side effects: |
| 768 |
* May cause the mouse position to be updated. |
| 769 |
* |
| 770 |
*---------------------------------------------------------------------- |
| 771 |
*/ |
| 772 |
|
| 773 |
void |
| 774 |
XChangeWindowAttributes(display, w, valueMask, attributes) |
| 775 |
Display* display; |
| 776 |
Window w; |
| 777 |
unsigned long valueMask; |
| 778 |
XSetWindowAttributes* attributes; |
| 779 |
{ |
| 780 |
if (valueMask & CWCursor) { |
| 781 |
XDefineCursor(display, w, attributes->cursor); |
| 782 |
} |
| 783 |
} |
| 784 |
|
| 785 |
/* |
| 786 |
*---------------------------------------------------------------------- |
| 787 |
* |
| 788 |
* TkWinSetWindowPos -- |
| 789 |
* |
| 790 |
* Adjust the stacking order of a window relative to a second |
| 791 |
* window (or NULL). |
| 792 |
* |
| 793 |
* Results: |
| 794 |
* None. |
| 795 |
* |
| 796 |
* Side effects: |
| 797 |
* Moves the specified window in the stacking order. |
| 798 |
* |
| 799 |
*---------------------------------------------------------------------- |
| 800 |
*/ |
| 801 |
|
| 802 |
void |
| 803 |
TkWinSetWindowPos(hwnd, siblingHwnd, pos) |
| 804 |
HWND hwnd; /* Window to restack. */ |
| 805 |
HWND siblingHwnd; /* Sibling window. */ |
| 806 |
int pos; /* One of Above or Below. */ |
| 807 |
{ |
| 808 |
HWND temp; |
| 809 |
|
| 810 |
/* |
| 811 |
* Since Windows does not support Above mode, we place the |
| 812 |
* specified window below the sibling and then swap them. |
| 813 |
*/ |
| 814 |
|
| 815 |
if (siblingHwnd) { |
| 816 |
if (pos == Above) { |
| 817 |
SetWindowPos(hwnd, siblingHwnd, 0, 0, 0, 0, |
| 818 |
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); |
| 819 |
temp = hwnd; |
| 820 |
hwnd = siblingHwnd; |
| 821 |
siblingHwnd = temp; |
| 822 |
} |
| 823 |
} else { |
| 824 |
siblingHwnd = (pos == Above) ? HWND_TOP : HWND_BOTTOM; |
| 825 |
} |
| 826 |
|
| 827 |
SetWindowPos(hwnd, siblingHwnd, 0, 0, 0, 0, |
| 828 |
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); |
| 829 |
} |
| 830 |
|
| 831 |
/* |
| 832 |
*---------------------------------------------------------------------- |
| 833 |
* |
| 834 |
* TkpWindowWasRecentlyDeleted -- |
| 835 |
* |
| 836 |
* Determines whether we know if the window given as argument was |
| 837 |
* recently deleted. Called by the generic code error handler to |
| 838 |
* handle BadWindow events. |
| 839 |
* |
| 840 |
* Results: |
| 841 |
* Always 0. We do not keep this information on Windows. |
| 842 |
* |
| 843 |
* Side effects: |
| 844 |
* None. |
| 845 |
* |
| 846 |
*---------------------------------------------------------------------- |
| 847 |
*/ |
| 848 |
|
| 849 |
int |
| 850 |
TkpWindowWasRecentlyDeleted(win, dispPtr) |
| 851 |
Window win; |
| 852 |
TkDisplay *dispPtr; |
| 853 |
{ |
| 854 |
return 0; |
| 855 |
} |
| 856 |
|
| 857 |
int |
| 858 |
XGetWindowAttributes(display, w, attrib) |
| 859 |
Display* display; |
| 860 |
Window w; |
| 861 |
XWindowAttributes* attrib; |
| 862 |
{ |
| 863 |
HWND hwnd = Tk_GetHWND(w); |
| 864 |
memset(attrib,0,sizeof(*attrib)); |
| 865 |
if (hwnd) { |
| 866 |
RECT rc; |
| 867 |
GetWindowRect(hwnd, &rc); |
| 868 |
attrib->width = rc.right - rc.left; |
| 869 |
attrib->height = rc.bottom - rc.top; |
| 870 |
attrib->x = rc.left; |
| 871 |
attrib->y = rc.top; |
| 872 |
return 1; |
| 873 |
} |
| 874 |
return 0; |
| 875 |
} |
| 876 |
|
| 877 |
|
| 878 |
|