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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 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 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 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 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 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 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
|
/*
* bltWindow.c --
*
* This module implements additional window functionality for
* the BLT toolkit, such as transparent Tk windows,
* and reparenting Tk windows.
*
* Copyright 1991-1998 Lucent Technologies, Inc.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and warranty
* disclaimer appear in supporting documentation, and that the names
* of Lucent Technologies any of their entities not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission.
*
* Lucent Technologies disclaims all warranties with regard to this
* software, including all implied warranties of merchantability and
* fitness. In no event shall Lucent Technologies be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether in
* an action of contract, negligence or other tortuous action, arising
* out of or in connection with the use or performance of this
* software.
*/
#include "bltInt.h"
#include <X11/Xlib.h>
#ifndef WIN32
#include <X11/Xproto.h>
#endif
#include <tkInt.h>
#ifdef XNQueryInputStyle
#define TK_USE_INPUT_METHODS
#endif
/*
* This defines whether we should try to use XIM over-the-spot style
* input. Allow users to override it. It is a much more elegant use
* of XIM, but uses a bit more memory.
*/
#ifndef TK_XIM_SPOT
# define TK_XIM_SPOT 1
#endif
#ifndef TK_REPARENTED
#define TK_REPARENTED 0
#endif
#ifdef WIN32
/*
*----------------------------------------------------------------------
*
* GetWindowHandle --
*
* Returns the XID for the Tk_Window given. Starting in Tk 8.0,
* the toplevel widgets are wrapped by another window.
* Currently there's no way to get at that window, other than
* what is done here: query the X window hierarchy and grab the
* parent.
*
* Results:
* Returns the X Window ID of the widget. If it's a toplevel, then
* the XID of the wrapper is returned.
*
*----------------------------------------------------------------------
*/
static HWND
GetWindowHandle(Tk_Window tkwin)
{
HWND hWnd;
Window window;
window = Tk_WindowId(tkwin);
if (window == None) {
Tk_MakeWindowExist(tkwin);
}
hWnd = Tk_GetHWND(Tk_WindowId(tkwin));
#if (TK_MAJOR_VERSION > 4)
if (Tk_IsTopLevel(tkwin)) {
hWnd = GetParent(hWnd);
}
#endif /* TK_MAJOR_VERSION > 4 */
return hWnd;
}
Window
Blt_GetParent(display, window)
Display *display;
Window window;
{
HWND hWnd;
hWnd = GetWindowHandle(window);
return (Window)hWnd;
}
#else
Window
Blt_GetParent(display, window)
Display *display;
Window window;
{
Window root, parent;
Window *dummy;
unsigned int count;
if (XQueryTree(display, window, &root, &parent, &dummy, &count) > 0) {
XFree(dummy);
return parent;
}
return None;
}
static Window
GetWindowId(tkwin)
Tk_Window tkwin;
{
Window window;
Tk_MakeWindowExist(tkwin);
window = Tk_WindowId(tkwin);
#if (TK_MAJOR_VERSION > 4)
if (Tk_IsTopLevel(tkwin)) {
Window parent;
parent = Blt_GetParent(Tk_Display(tkwin), window);
if (parent != None && parent != XRootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin))) {
window = parent;
}
/*window = parent; */
}
#endif /* TK_MAJOR_VERSION > 4 */
return window;
}
#endif /* WIN32 */
/*
*----------------------------------------------------------------------
*
* DoConfigureNotify --
*
* Generate a ConfigureNotify event describing the current
* configuration of a window.
*
* Results:
* None.
*
* Side effects:
* An event is generated and processed by Tk_HandleEvent.
*
*----------------------------------------------------------------------
*/
static void
DoConfigureNotify(winPtr)
Tk_FakeWin *winPtr; /* Window whose configuration was just
* changed. */
{
XEvent event;
event.type = ConfigureNotify;
event.xconfigure.serial = LastKnownRequestProcessed(winPtr->display);
event.xconfigure.send_event = False;
event.xconfigure.display = winPtr->display;
event.xconfigure.event = winPtr->window;
event.xconfigure.window = winPtr->window;
event.xconfigure.x = winPtr->changes.x;
event.xconfigure.y = winPtr->changes.y;
event.xconfigure.width = winPtr->changes.width;
event.xconfigure.height = winPtr->changes.height;
event.xconfigure.border_width = winPtr->changes.border_width;
if (winPtr->changes.stack_mode == Above) {
event.xconfigure.above = winPtr->changes.sibling;
} else {
event.xconfigure.above = None;
}
event.xconfigure.override_redirect = winPtr->atts.override_redirect;
Tk_HandleEvent(&event);
}
/*
*--------------------------------------------------------------
*
* Blt_MakeTransparentWindowExist --
*
* Similar to Tk_MakeWindowExist but instead creates a
* transparent window to block for user events from sibling
* windows.
*
* Differences from Tk_MakeWindowExist.
*
* 1. This is always a "busy" window. There's never a
* platform-specific class procedure to execute instead.
* 2. The window is transparent and never will contain children,
* so colormap information is irrelevant.
*
* Results:
* None.
*
* Side effects:
* When the procedure returns, the internal window associated
* with tkwin is guaranteed to exist. This may require the
* window's ancestors to be created too.
*
*--------------------------------------------------------------
*/
void
Blt_MakeTransparentWindowExist(tkwin, parent, isBusy)
Tk_Window tkwin; /* Token for window. */
Window parent; /* Parent window. */
int isBusy; /* */
{
TkWindow *winPtr = (TkWindow *) tkwin;
TkWindow *winPtr2;
Tcl_HashEntry *hPtr;
int notUsed;
TkDisplay *dispPtr;
#ifdef WIN32
HWND hParent;
int style;
DWORD exStyle;
HWND hWnd;
#else
long int mask;
#endif /* WIN32 */
if (winPtr->window != None) {
return; /* Window already exists. */
}
#ifdef notdef
if ((winPtr->parentPtr == NULL) || (winPtr->flags & TK_TOP_LEVEL)) {
parent = XRootWindow(winPtr->display, winPtr->screenNum);
/* TODO: Make the entire screen busy */
} else {
if (Tk_WindowId(winPtr->parentPtr) == None) {
Tk_MakeWindowExist((Tk_Window)winPtr->parentPtr);
}
}
#endif
/* Create a transparent window and put it on top. */
#ifdef WIN32
hParent = (HWND) parent;
style = (WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
exStyle = (WS_EX_TRANSPARENT | WS_EX_TOPMOST);
#define TK_WIN_CHILD_CLASS_NAME "TkChild"
hWnd = CreateWindowEx(exStyle, TK_WIN_CHILD_CLASS_NAME, NULL, style,
Tk_X(tkwin), Tk_Y(tkwin), Tk_Width(tkwin), Tk_Height(tkwin),
hParent, NULL, (HINSTANCE) Tk_GetHINSTANCE(), NULL);
winPtr->window = Tk_AttachHWND(tkwin, hWnd);
#else
mask = (!isBusy) ? 0 : (CWDontPropagate | CWEventMask);
/* Ignore the important events while the window is mapped. */
#define USER_EVENTS (EnterWindowMask | LeaveWindowMask | KeyPressMask | \
KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
#define PROP_EVENTS (KeyPressMask | KeyReleaseMask | ButtonPressMask | \
ButtonReleaseMask | PointerMotionMask)
winPtr->atts.do_not_propagate_mask = PROP_EVENTS;
winPtr->atts.event_mask = USER_EVENTS;
winPtr->changes.border_width = 0;
winPtr->depth = 0;
winPtr->window = XCreateWindow(winPtr->display, parent,
winPtr->changes.x, winPtr->changes.y,
(unsigned)winPtr->changes.width, /* width */
(unsigned)winPtr->changes.height, /* height */
(unsigned)winPtr->changes.border_width, /* border_width */
winPtr->depth, /* depth */
InputOnly, /* class */
winPtr->visual, /* visual */
mask, /* valuemask */
&(winPtr->atts) /* attributes */ );
#endif /* WIN32 */
dispPtr = winPtr->dispPtr;
hPtr = Tcl_CreateHashEntry(&(dispPtr->winTable), (char *)winPtr->window,
¬Used);
Tcl_SetHashValue(hPtr, winPtr);
winPtr->dirtyAtts = 0;
winPtr->dirtyChanges = 0;
#ifdef TK_USE_INPUT_METHODS
winPtr->inputContext = NULL;
#endif /* TK_USE_INPUT_METHODS */
if (!(winPtr->flags & TK_TOP_LEVEL)) {
/*
* If any siblings higher up in the stacking order have already
* been created then move this window to its rightful position
* in the stacking order.
*
* NOTE: this code ignores any changes anyone might have made
* to the sibling and stack_mode field of the window's attributes,
* so it really isn't safe for these to be manipulated except
* by calling Tk_RestackWindow.
*/
for (winPtr2 = winPtr->nextPtr; winPtr2 != NULL;
winPtr2 = winPtr2->nextPtr) {
if ((winPtr2->window != None) && !(winPtr2->flags & TK_TOP_LEVEL)) {
XWindowChanges changes;
changes.sibling = winPtr2->window;
changes.stack_mode = Below;
XConfigureWindow(winPtr->display, winPtr->window,
CWSibling | CWStackMode, &changes);
break;
}
}
}
/*
* Issue a ConfigureNotify event if there were deferred configuration
* changes (but skip it if the window is being deleted; the
* ConfigureNotify event could cause problems if we're being called
* from Tk_DestroyWindow under some conditions).
*/
if ((winPtr->flags & TK_NEED_CONFIG_NOTIFY)
&& !(winPtr->flags & TK_ALREADY_DEAD)) {
winPtr->flags &= ~TK_NEED_CONFIG_NOTIFY;
DoConfigureNotify((Tk_FakeWin *) tkwin);
}
}
/*
*----------------------------------------------------------------------
*
* Blt_FindChild --
*
* Performs a linear search for the named child window in a given
* parent window.
*
* This can be done via Tcl, but not through Tk's C API. It's
* simple enough, if you peek into the Tk_Window structure.
*
* Results:
* The child Tk_Window. If the named child can't be found, NULL
* is returned.
*
*----------------------------------------------------------------------
*/
/*LINTLIBRARY*/
Tk_Window
Blt_FindChild(parent, name)
Tk_Window parent;
char *name;
{
register TkWindow *winPtr;
TkWindow *parentPtr = (TkWindow *)parent;
for (winPtr = parentPtr->childList; winPtr != NULL;
winPtr = winPtr->nextPtr) {
if (strcmp(name, winPtr->nameUid) == 0) {
return (Tk_Window)winPtr;
}
}
return NULL;
}
/*
*----------------------------------------------------------------------
*
* Blt_FirstChildWindow --
*
* Performs a linear search for the named child window in a given
* parent window.
*
* This can be done via Tcl, but not through Tk's C API. It's
* simple enough, if you peek into the Tk_Window structure.
*
* Results:
* The child Tk_Window. If the named child can't be found, NULL
* is returned.
*
*----------------------------------------------------------------------
*/
/*LINTLIBRARY*/
Tk_Window
Blt_FirstChild(parent)
Tk_Window parent;
{
TkWindow *parentPtr = (TkWindow *)parent;
return (Tk_Window)parentPtr->childList;
}
/*
*----------------------------------------------------------------------
*
* Blt_FindChild --
*
* Performs a linear search for the named child window in a given
* parent window.
*
* This can be done via Tcl, but not through Tk's C API. It's
* simple enough, if you peek into the Tk_Window structure.
*
* Results:
* The child Tk_Window. If the named child can't be found, NULL
* is returned.
*
*----------------------------------------------------------------------
*/
/*LINTLIBRARY*/
Tk_Window
Blt_NextChild(tkwin)
Tk_Window tkwin;
{
TkWindow *winPtr = (TkWindow *)tkwin;
if (winPtr == NULL) {
return NULL;
}
return (Tk_Window)winPtr->nextPtr;
}
/*
*----------------------------------------------------------------------
*
* UnlinkWindow --
*
* This procedure removes a window from the childList of its
* parent.
*
* Results:
* None.
*
* Side effects:
* The window is unlinked from its childList.
*
*----------------------------------------------------------------------
*/
static void
UnlinkWindow(winPtr)
TkWindow *winPtr; /* Child window to be unlinked. */
{
TkWindow *prevPtr;
prevPtr = winPtr->parentPtr->childList;
if (prevPtr == winPtr) {
winPtr->parentPtr->childList = winPtr->nextPtr;
if (winPtr->nextPtr == NULL) {
winPtr->parentPtr->lastChildPtr = NULL;
}
} else {
while (prevPtr->nextPtr != winPtr) {
prevPtr = prevPtr->nextPtr;
if (prevPtr == NULL) {
panic("UnlinkWindow couldn't find child in parent");
}
}
prevPtr->nextPtr = winPtr->nextPtr;
if (winPtr->nextPtr == NULL) {
winPtr->parentPtr->lastChildPtr = prevPtr;
}
}
}
/*
*----------------------------------------------------------------------
*
* Blt_RelinkWindow --
*
* Relinks a window into a new parent. The window is unlinked
* from its original parent's child list and added onto the end
* of the new parent's list.
*
* FIXME: If the window has focus, the focus should be moved
* to an ancestor. Otherwise, Tk becomes confused
* about which Toplevel turns on focus for the window.
* Right now this is done at the Tcl layer. For example,
* see blt::CreateTearoff in tabset.tcl.
*
* Results:
* None.
*
* Side effects:
* The window is unlinked from its childList.
*
*----------------------------------------------------------------------
*/
void
Blt_RelinkWindow(tkwin, newParent, x, y)
Tk_Window tkwin; /* Child window to be linked. */
Tk_Window newParent;
int x, y;
{
TkWindow *winPtr, *parentWinPtr;
if (Blt_ReparentWindow(Tk_Display(tkwin), Tk_WindowId(tkwin),
Tk_WindowId(newParent), x, y) != TCL_OK) {
return;
}
winPtr = (TkWindow *)tkwin;
parentWinPtr = (TkWindow *)newParent;
winPtr->flags &= ~TK_REPARENTED;
UnlinkWindow(winPtr); /* Remove the window from its parent's list */
/* Append the window onto the end of the parent's list of children */
winPtr->parentPtr = parentWinPtr;
winPtr->nextPtr = NULL;
if (parentWinPtr->childList == NULL) {
parentWinPtr->childList = winPtr;
} else {
parentWinPtr->lastChildPtr->nextPtr = winPtr;
}
parentWinPtr->lastChildPtr = winPtr;
}
/*
*----------------------------------------------------------------------
*
* Blt_RelinkWindow --
*
* Relinks a window into a new parent. The window is unlinked
* from its original parent's child list and added onto the end
* of the new parent's list.
*
* FIXME: If the window has focus, the focus should be moved
* to an ancestor. Otherwise, Tk becomes confused
* about which Toplevel turns on focus for the window.
* Right now this is done at the Tcl layer. For example,
* see blt::CreateTearoff in tabset.tcl.
*
* Results:
* None.
*
* Side effects:
* The window is unlinked from its childList.
*
*----------------------------------------------------------------------
*/
void
Blt_RelinkWindow2(tkwin, window, newParent, x, y)
Tk_Window tkwin; /* Child window to be linked. */
Window window;
Tk_Window newParent;
int x, y;
{
#ifdef notdef
TkWindow *winPtr, *parentWinPtr;
#endif
if (Blt_ReparentWindow(Tk_Display(tkwin), window,
Tk_WindowId(newParent), x, y) != TCL_OK) {
return;
}
#ifdef notdef
winPtr = (TkWindow *)tkwin;
parentWinPtr = (TkWindow *)newParent;
winPtr->flags &= ~TK_REPARENTED;
UnlinkWindow(winPtr); /* Remove the window from its parent's list */
/* Append the window onto the end of the parent's list of children */
winPtr->parentPtr = parentWinPtr;
winPtr->nextPtr = NULL;
if (parentWinPtr->childList == NULL) {
parentWinPtr->childList = winPtr;
} else {
parentWinPtr->lastChildPtr->nextPtr = winPtr;
}
parentWinPtr->lastChildPtr = winPtr;
#endif
}
void
Blt_UnlinkWindow(tkwin)
Tk_Window tkwin; /* Child window to be linked. */
{
TkWindow *winPtr;
Window root;
root = XRootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
if (Blt_ReparentWindow(Tk_Display(tkwin), Tk_WindowId(tkwin),
root, 0, 0) != TCL_OK) {
return;
}
winPtr = (TkWindow *)tkwin;
winPtr->flags &= ~TK_REPARENTED;
#ifdef notdef
UnlinkWindow(winPtr); /* Remove the window from its parent's list */
#endif
}
/*
*----------------------------------------------------------------------
*
* Blt_Toplevel --
*
* Climbs up the widget hierarchy to find the top level window of
* the window given.
*
* Results:
* Returns the Tk_Window of the toplevel widget.
*
*----------------------------------------------------------------------
*/
Tk_Window
Blt_Toplevel(tkwin)
register Tk_Window tkwin;
{
while (!Tk_IsTopLevel(tkwin)) {
tkwin = Tk_Parent(tkwin);
}
return tkwin;
}
void
Blt_RootCoordinates(tkwin, x, y, rootXPtr, rootYPtr)
Tk_Window tkwin;
int x, y;
int *rootXPtr, *rootYPtr;
{
int vx, vy, vw, vh;
int rootX, rootY;
Tk_GetRootCoords(tkwin, &rootX, &rootY);
x += rootX;
y += rootY;
Tk_GetVRootGeometry(tkwin, &vx, &vy, &vw, &vh);
x += vx;
y += vy;
*rootXPtr = x;
*rootYPtr = y;
}
/* Find the toplevel then */
int
Blt_RootX(tkwin)
Tk_Window tkwin;
{
int x;
for (x = 0; tkwin != NULL; tkwin = Tk_Parent(tkwin)) {
x += Tk_X(tkwin) + Tk_Changes(tkwin)->border_width;
if (Tk_IsTopLevel(tkwin)) {
break;
}
}
return x;
}
int
Blt_RootY(tkwin)
Tk_Window tkwin;
{
int y;
for (y = 0; tkwin != NULL; tkwin = Tk_Parent(tkwin)) {
y += Tk_Y(tkwin) + Tk_Changes(tkwin)->border_width;
if (Tk_IsTopLevel(tkwin)) {
break;
}
}
return y;
}
#ifdef WIN32
/*
*----------------------------------------------------------------------
*
* Blt_GetRealWindowId --
*
* Returns the XID for the Tk_Window given. Starting in Tk 8.0,
* the toplevel widgets are wrapped by another window.
* Currently there's no way to get at that window, other than
* what is done here: query the X window hierarchy and grab the
* parent.
*
* Results:
* Returns the X Window ID of the widget. If it's a toplevel, then
* the XID of the wrapper is returned.
*
*----------------------------------------------------------------------
*/
Window
Blt_GetRealWindowId(Tk_Window tkwin)
{
return (Window) GetWindowHandle(tkwin);
}
/*
*----------------------------------------------------------------------
*
* Blt_GetToplevel --
*
* Retrieves the toplevel window which is the nearest ancestor of
* of the specified window.
*
* Results:
* Returns the toplevel window or NULL if the window has no
* ancestor which is a toplevel.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
Tk_Window
Blt_GetToplevel(Tk_Window tkwin) /* Window for which the toplevel
* should be deterined. */
{
while (!Tk_IsTopLevel(tkwin)) {
tkwin = Tk_Parent(tkwin);
if (tkwin == NULL) {
return NULL;
}
}
return tkwin;
}
/*
*----------------------------------------------------------------------
*
* Blt_RaiseToLevelWindow --
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
Blt_RaiseToplevel(Tk_Window tkwin)
{
SetWindowPos(GetWindowHandle(tkwin), HWND_TOP, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE);
}
/*
*----------------------------------------------------------------------
*
* Blt_MapToplevel --
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
Blt_MapToplevel(Tk_Window tkwin)
{
ShowWindow(GetWindowHandle(tkwin), SW_SHOWNORMAL);
}
/*
*----------------------------------------------------------------------
*
* Blt_UnmapToplevel --
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
Blt_UnmapToplevel(Tk_Window tkwin)
{
ShowWindow(GetWindowHandle(tkwin), SW_HIDE);
}
/*
*----------------------------------------------------------------------
*
* Blt_MoveResizeToplevel --
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
Blt_MoveResizeToplevel(tkwin, x, y, width, height)
Tk_Window tkwin;
int x, y, width, height;
{
SetWindowPos(GetWindowHandle(tkwin), HWND_TOP, x, y, width, height, 0);
}
int
Blt_ReparentWindow(
Display *display,
Window window,
Window newParent,
int x, int y)
{
XReparentWindow(display, window, newParent, x, y);
return TCL_OK;
}
#else /* WIN32 */
/*
*----------------------------------------------------------------------
*
* Blt_GetRealWindowId --
*
* Returns the XID for the Tk_Window given. Starting in Tk 8.0,
* the toplevel widgets are wrapped by another window.
* Currently there's no way to get at that window, other than
* what is done here: query the X window hierarchy and grab the
* parent.
*
* Results:
* Returns the X Window ID of the widget. If it's a toplevel, then
* the XID of the wrapper is returned.
*
*----------------------------------------------------------------------
*/
Window
Blt_GetRealWindowId(tkwin)
Tk_Window tkwin;
{
return GetWindowId(tkwin);
}
/*
*----------------------------------------------------------------------
*
* Blt_RaiseToplevel --
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
Blt_RaiseToplevel(tkwin)
Tk_Window tkwin;
{
XRaiseWindow(Tk_Display(tkwin), GetWindowId(tkwin));
}
/*
*----------------------------------------------------------------------
*
* Blt_LowerToplevel --
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
Blt_LowerToplevel(tkwin)
Tk_Window tkwin;
{
XLowerWindow(Tk_Display(tkwin), GetWindowId(tkwin));
}
/*
*----------------------------------------------------------------------
*
* Blt_ResizeToplevel --
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
Blt_ResizeToplevel(tkwin, width, height)
Tk_Window tkwin;
int width, height;
{
XResizeWindow(Tk_Display(tkwin), GetWindowId(tkwin), width, height);
}
/*
*----------------------------------------------------------------------
*
* Blt_MoveResizeToplevel --
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
Blt_MoveResizeToplevel(tkwin, x, y, width, height)
Tk_Window tkwin;
int x, y, width, height;
{
XMoveResizeWindow(Tk_Display(tkwin), GetWindowId(tkwin), x, y,
width, height);
}
/*
*----------------------------------------------------------------------
*
* Blt_ResizeToplevel --
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
Blt_MoveToplevel(tkwin, x, y)
Tk_Window tkwin;
int x, y;
{
XMoveWindow(Tk_Display(tkwin), GetWindowId(tkwin), x, y);
}
/*
*----------------------------------------------------------------------
*
* Blt_MapToplevel --
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
Blt_MapToplevel(tkwin)
Tk_Window tkwin;
{
XMapWindow(Tk_Display(tkwin), GetWindowId(tkwin));
}
/*
*----------------------------------------------------------------------
*
* Blt_UnmapToplevel --
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
void
Blt_UnmapToplevel(tkwin)
Tk_Window tkwin;
{
XUnmapWindow(Tk_Display(tkwin), GetWindowId(tkwin));
}
/* ARGSUSED */
static int
XReparentWindowErrorProc(clientData, errEventPtr)
ClientData clientData;
XErrorEvent *errEventPtr;
{
int *errorPtr = clientData;
*errorPtr = TCL_ERROR;
return 0;
}
int
Blt_ReparentWindow(display, window, newParent, x, y)
Display *display;
Window window, newParent;
int x, y;
{
Tk_ErrorHandler handler;
int result;
int any = -1;
result = TCL_OK;
handler = Tk_CreateErrorHandler(display, any, X_ReparentWindow, any,
XReparentWindowErrorProc, &result);
XReparentWindow(display, window, newParent, x, y);
Tk_DeleteErrorHandler(handler);
XSync(display, False);
return result;
}
#endif /* WIN32 */
#if (TK_MAJOR_VERSION == 4)
#include <bltHash.h>
static int initialized = FALSE;
static Blt_HashTable windowTable;
void
Blt_SetWindowInstanceData(tkwin, instanceData)
Tk_Window tkwin;
ClientData instanceData;
{
Blt_HashEntry *hPtr;
int isNew;
if (!initialized) {
Blt_InitHashTable(&windowTable, BLT_ONE_WORD_KEYS);
initialized = TRUE;
}
hPtr = Blt_CreateHashEntry(&windowTable, (char *)tkwin, &isNew);
assert(isNew);
Blt_SetHashValue(hPtr, instanceData);
}
ClientData
Blt_GetWindowInstanceData(tkwin)
Tk_Window tkwin;
{
Blt_HashEntry *hPtr;
hPtr = Blt_FindHashEntry(&windowTable, (char *)tkwin);
if (hPtr == NULL) {
return NULL;
}
return Blt_GetHashValue(hPtr);
}
void
Blt_DeleteWindowInstanceData(tkwin)
Tk_Window tkwin;
{
Blt_HashEntry *hPtr;
hPtr = Blt_FindHashEntry(&windowTable, (char *)tkwin);
assert(hPtr);
Blt_DeleteHashEntry(&windowTable, hPtr);
}
#else
void
Blt_SetWindowInstanceData(tkwin, instanceData)
Tk_Window tkwin;
ClientData instanceData;
{
TkWindow *winPtr = (TkWindow *)tkwin;
winPtr->instanceData = instanceData;
}
ClientData
Blt_GetWindowInstanceData(tkwin)
Tk_Window tkwin;
{
TkWindow *winPtr = (TkWindow *)tkwin;
return winPtr->instanceData;
}
void
Blt_DeleteWindowInstanceData(tkwin)
Tk_Window tkwin;
{
}
#endif
|