Debian Codegraph @

generic/bltWindow.c

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /*
2 * bltWindow.c --
3 *
4 * This module implements additional window functionality for
5 * the BLT toolkit, such as transparent Tk windows,
6 * and reparenting Tk windows.
7 *
8 * Copyright 1991-1998 Lucent Technologies, Inc.
9 *
10 * Permission to use, copy, modify, and distribute this software and
11 * its documentation for any purpose and without fee is hereby
12 * granted, provided that the above copyright notice appear in all
13 * copies and that both that the copyright notice and warranty
14 * disclaimer appear in supporting documentation, and that the names
15 * of Lucent Technologies any of their entities not be used in
16 * advertising or publicity pertaining to distribution of the software
17 * without specific, written prior permission.
18 *
19 * Lucent Technologies disclaims all warranties with regard to this
20 * software, including all implied warranties of merchantability and
21 * fitness. In no event shall Lucent Technologies be liable for any
22 * special, indirect or consequential damages or any damages
23 * whatsoever resulting from loss of use, data or profits, whether in
24 * an action of contract, negligence or other tortuous action, arising
25 * out of or in connection with the use or performance of this
26 * software.
27 */
28
29 #include "bltInt.h"
30
31 #include <X11/Xlib.h>
32 #ifndef WIN32
33 #include <X11/Xproto.h>
34 #endif
35
36 typedef struct TkIdStackStruct TkIdStack;
37 typedef struct TkErrorHandlerStruct TkErrorHandler;
38 typedef struct TkSelectionInfoStruct TkSelectionInfo;
39 typedef struct TkClipboardTargetStruct TkClipboardTarget;
40
41 #ifndef WIN32
42 typedef struct TkWindowStruct TkWindow;
43 #endif
44 typedef struct TkWindowEventStruct TkWindowEvent;
45 typedef struct TkMainInfoStruct TkMainInfo;
46 typedef struct TkEventHandlerStruct TkEventHandler;
47 typedef struct TkSelHandlerStruct TkSelHandler;
48 typedef struct TkWinInfoStruct TkWinInfo;
49 typedef struct TkClassProcsStruct TkClassProcs;
50 typedef struct TkWindowPrivateStruct TkWindowPrivate;
51 typedef struct TkGrabEventStruct TkGrabEvent;
52 typedef struct TkColormapStruct TkColormap;
53 typedef struct TkStressedCmapStruct TkStressedCmap;
54 typedef struct TkWmInfoStruct TkWmInfo;
55
56 #ifdef XNQueryInputStyle
57 #define TK_USE_INPUT_METHODS
58 #endif
59
60 /*
61 * This defines whether we should try to use XIM over-the-spot style
62 * input. Allow users to override it. It is a much more elegant use
63 * of XIM, but uses a bit more memory.
64 */
65 #ifndef TK_XIM_SPOT
66 # define TK_XIM_SPOT 1
67 #endif
68
69 #ifndef TK_REPARENTED
70 #define TK_REPARENTED 0
71 #endif
72
73 #if (TK_VERSION_NUMBER >= _VERSION(8,1,0))
74
75 typedef struct TkCaret {
76 struct TkWindow *winPtr; /* the window on which we requested caret
77 * placement */
78 int x; /* relative x coord of the caret */
79 int y; /* relative y coord of the caret */
80 int height; /* specified height of the window */
81 } TkCaret;
82
83 /*
84 * One of the following structures is maintained for each display
85 * containing a window managed by Tk. In part, the structure is
86 * used to store thread-specific data, since each thread will have
87 * its own TkDisplay structure.
88 */
89
90 typedef struct TkDisplayStruct {
91 Display *display; /* Xlib's info about display. */
92 struct TkDisplayStruct *nextPtr; /* Next in list of all displays. */
93 char *name; /* Name of display (with any screen
94 * identifier removed). Malloc-ed. */
95 Time lastEventTime; /* Time of last event received for this
96 * display. */
97
98 /*
99 * Information used primarily by tk3d.c:
100 */
101
102 int borderInit; /* 0 means borderTable needs initializing. */
103 Tcl_HashTable borderTable; /* Maps from color name to TkBorder
104 * structure. */
105
106 /*
107 * Information used by tkAtom.c only:
108 */
109
110 int atomInit; /* 0 means stuff below hasn't been
111 * initialized yet. */
112 Tcl_HashTable nameTable; /* Maps from names to Atom's. */
113 Tcl_HashTable atomTable; /* Maps from Atom's back to names. */
114
115 /*
116 * Information used primarily by tkBind.c:
117 */
118
119 int bindInfoStale; /* Non-zero means the variables in this
120 * part of the structure are potentially
121 * incorrect and should be recomputed. */
122 unsigned int modeModMask; /* Has one bit set to indicate the modifier
123 * corresponding to "mode shift". If no
124 * such modifier, than this is zero. */
125 unsigned int metaModMask; /* Has one bit set to indicate the modifier
126 * corresponding to the "Meta" key. If no
127 * such modifier, then this is zero. */
128 unsigned int altModMask; /* Has one bit set to indicate the modifier
129 * corresponding to the "Meta" key. If no
130 * such modifier, then this is zero. */
131 enum {
132 LU_IGNORE, LU_CAPS, LU_SHIFT
133 } lockUsage; /* Indicates how to interpret lock modifier. */
134 int numModKeyCodes; /* Number of entries in modKeyCodes array
135 * below. */
136 KeyCode *modKeyCodes; /* Pointer to an array giving keycodes for
137 * all of the keys that have modifiers
138 * associated with them. Malloc'ed, but
139 * may be NULL. */
140
141 /*
142 * Information used by tkBitmap.c only:
143 */
144
145 int bitmapInit; /* 0 means tables above need initializing. */
146 int bitmapAutoNumber; /* Used to number bitmaps. */
147 Tcl_HashTable bitmapNameTable;
148 /* Maps from name of bitmap to the first
149 * TkBitmap record for that name. */
150 Tcl_HashTable bitmapIdTable;/* Maps from bitmap id to the TkBitmap
151 * structure for the bitmap. */
152 Tcl_HashTable bitmapDataTable;
153 /* Used by Tk_GetBitmapFromData to map from
154 * a collection of in-core data about a
155 * bitmap to a reference giving an auto-
156 * matically-generated name for the bitmap. */
157
158 /*
159 * Information used by tkCanvas.c only:
160 */
161
162 int numIdSearches;
163 int numSlowSearches;
164
165 /*
166 * Used by tkColor.c only:
167 */
168
169 int colorInit; /* 0 means color module needs initializing. */
170 TkStressedCmap *stressPtr; /* First in list of colormaps that have
171 * filled up, so we have to pick an
172 * approximate color. */
173 Tcl_HashTable colorNameTable;
174 /* Maps from color name to TkColor structure
175 * for that color. */
176 Tcl_HashTable colorValueTable;
177 /* Maps from integer RGB values to TkColor
178 * structures. */
179
180 /*
181 * Used by tkCursor.c only:
182 */
183
184 int cursorInit; /* 0 means cursor module need initializing. */
185 Tcl_HashTable cursorNameTable;
186 /* Maps from a string name to a cursor to the
187 * TkCursor record for the cursor. */
188 Tcl_HashTable cursorDataTable;
189 /* Maps from a collection of in-core data
190 * about a cursor to a TkCursor structure. */
191 Tcl_HashTable cursorIdTable;
192 /* Maps from a cursor id to the TkCursor
193 * structure for the cursor. */
194 char cursorString[20]; /* Used to store a cursor id string. */
195 Font cursorFont; /* Font to use for standard cursors.
196 * None means font not loaded yet. */
197
198 /*
199 * Information used by tkError.c only:
200 */
201
202 struct TkErrorHandler *errorPtr;
203 /* First in list of error handlers
204 * for this display. NULL means
205 * no handlers exist at present. */
206 int deleteCount; /* Counts # of handlers deleted since
207 * last time inactive handlers were
208 * garbage-collected. When this number
209 * gets big, handlers get cleaned up. */
210
211 /*
212 * Used by tkEvent.c only:
213 */
214
215 struct TkWindowEvent *delayedMotionPtr;
216 /* Points to a malloc-ed motion event
217 * whose processing has been delayed in
218 * the hopes that another motion event
219 * will come along right away and we can
220 * merge the two of them together. NULL
221 * means that there is no delayed motion
222 * event. */
223
224 /*
225 * Information used by tkFocus.c only:
226 */
227
228 int focusDebug; /* 1 means collect focus debugging
229 * statistics. */
230 struct TkWindow *implicitWinPtr;
231 /* If the focus arrived at a toplevel window
232 * implicitly via an Enter event (rather
233 * than via a FocusIn event), this points
234 * to the toplevel window. Otherwise it is
235 * NULL. */
236 struct TkWindow *focusPtr; /* Points to the window on this display that
237 * should be receiving keyboard events. When
238 * multiple applications on the display have
239 * the focus, this will refer to the
240 * innermost window in the innermost
241 * application. This information isn't used
242 * under Unix or Windows, but it's needed on
243 * the Macintosh. */
244
245 /*
246 * Information used by tkGC.c only:
247 */
248
249 Tcl_HashTable gcValueTable; /* Maps from a GC's values to a TkGC structure
250 * describing a GC with those values. */
251 Tcl_HashTable gcIdTable; /* Maps from a GC to a TkGC. */
252 int gcInit; /* 0 means the tables below need
253 * initializing. */
254
255 /*
256 * Information used by tkGeometry.c only:
257 */
258
259 Tcl_HashTable maintainHashTable;
260 /* Hash table that maps from a master's
261 * Tk_Window token to a list of slaves
262 * managed by that master. */
263 int geomInit;
264
265 /*
266 * Information used by tkGet.c only:
267 */
268
269 Tcl_HashTable uidTable; /* Stores all Tk_Uids used in a thread. */
270 int uidInit; /* 0 means uidTable needs initializing. */
271
272 /*
273 * Information used by tkGrab.c only:
274 */
275
276 struct TkWindow *grabWinPtr;
277 /* Window in which the pointer is currently
278 * grabbed, or NULL if none. */
279 struct TkWindow *eventualGrabWinPtr;
280 /* Value that grabWinPtr will have once the
281 * grab event queue (below) has been
282 * completely emptied. */
283 struct TkWindow *buttonWinPtr;
284 /* Window in which first mouse button was
285 * pressed while grab was in effect, or NULL
286 * if no such press in effect. */
287 struct TkWindow *serverWinPtr;
288 /* If no application contains the pointer then
289 * this is NULL. Otherwise it contains the
290 * last window for which we've gotten an
291 * Enter or Leave event from the server (i.e.
292 * the last window known to have contained
293 * the pointer). Doesn't reflect events
294 * that were synthesized in tkGrab.c. */
295 TkGrabEvent *firstGrabEventPtr;
296 /* First in list of enter/leave events
297 * synthesized by grab code. These events
298 * must be processed in order before any other
299 * events are processed. NULL means no such
300 * events. */
301 TkGrabEvent *lastGrabEventPtr;
302 /* Last in list of synthesized events, or NULL
303 * if list is empty. */
304 int grabFlags; /* Miscellaneous flag values. See definitions
305 * in tkGrab.c. */
306
307 /*
308 * Information used by tkGrid.c only:
309 */
310
311 int gridInit; /* 0 means table below needs initializing. */
312 Tcl_HashTable gridHashTable;/* Maps from Tk_Window tokens to
313 * corresponding Grid structures. */
314
315 /*
316 * Information used by tkImage.c only:
317 */
318
319 int imageId; /* Value used to number image ids. */
320
321 /*
322 * Information used by tkMacWinMenu.c only:
323 */
324
325 int postCommandGeneration;
326
327 /*
328 * Information used by tkOption.c only.
329 */
330
331
332
333 /*
334 * Information used by tkPack.c only.
335 */
336
337 int packInit; /* 0 means table below needs initializing. */
338 Tcl_HashTable packerHashTable;
339 /* Maps from Tk_Window tokens to
340 * corresponding Packer structures. */
341
342
343 /*
344 * Information used by tkPlace.c only.
345 */
346
347 int placeInit; /* 0 means tables below need initializing. */
348 Tcl_HashTable masterTable; /* Maps from Tk_Window toke to the Master
349 * structure for the window, if it exists. */
350 Tcl_HashTable slaveTable; /* Maps from Tk_Window toke to the Slave
351 * structure for the window, if it exists. */
352
353 /*
354 * Information used by tkSelect.c and tkClipboard.c only:
355 */
356
357
358 struct TkSelectionInfo *selectionInfoPtr;
359 /* First in list of selection information
360 * records. Each entry contains information
361 * about the current owner of a particular
362 * selection on this display. */
363 Atom multipleAtom; /* Atom for MULTIPLE. None means
364 * selection stuff isn't initialized. */
365 Atom incrAtom; /* Atom for INCR. */
366 Atom targetsAtom; /* Atom for TARGETS. */
367 Atom timestampAtom; /* Atom for TIMESTAMP. */
368 Atom textAtom; /* Atom for TEXT. */
369 Atom compoundTextAtom; /* Atom for COMPOUND_TEXT. */
370 Atom applicationAtom; /* Atom for TK_APPLICATION. */
371 Atom windowAtom; /* Atom for TK_WINDOW. */
372 Atom clipboardAtom; /* Atom for CLIPBOARD. */
373 #if (TK_VERSION_NUMBER >= _VERSION(8,4,0))
374 Atom utf8Atom;
375 #endif
376 Tk_Window clipWindow; /* Window used for clipboard ownership and to
377 * retrieve selections between processes. NULL
378 * means clipboard info hasn't been
379 * initialized. */
380 int clipboardActive; /* 1 means we currently own the clipboard
381 * selection, 0 means we don't. */
382 struct TkMainInfo *clipboardAppPtr;
383 /* Last application that owned clipboard. */
384 struct TkClipboardTarget *clipTargetPtr;
385 /* First in list of clipboard type information
386 * records. Each entry contains information
387 * about the buffers for a given selection
388 * target. */
389
390 /*
391 * Information used by tkSend.c only:
392 */
393
394 Tk_Window commTkwin; /* Window used for communication
395 * between interpreters during "send"
396 * commands. NULL means send info hasn't
397 * been initialized yet. */
398 Atom commProperty; /* X's name for comm property. */
399 Atom registryProperty; /* X's name for property containing
400 * registry of interpreter names. */
401 Atom appNameProperty; /* X's name for property used to hold the
402 * application name on each comm window. */
403
404 /*
405 * Information used by tkXId.c only:
406 */
407
408 struct TkIdStack *idStackPtr;
409 /* First in list of chunks of free resource
410 * identifiers, or NULL if there are no free
411 * resources. */
412 XID(*defaultAllocProc) _ANSI_ARGS_((Display *display));
413 /* Default resource allocator for display. */
414 struct TkIdStack *windowStackPtr;
415 /* First in list of chunks of window
416 * identifers that can't be reused right
417 * now. */
418 #if (TK_VERSION_NUMBER < _VERSION(8,4,0))
419 int idCleanupScheduled; /* 1 means a call to WindowIdCleanup has
420 * already been scheduled, 0 means it
421 * hasn't. */
422 #else
423 Tcl_TimerToken idCleanupScheduled;
424 /* If set, it means a call to WindowIdCleanup
425 * has already been scheduled, 0 means it
426 * hasn't. */
427 #endif
428 /*
429 * Information used by tkUnixWm.c and tkWinWm.c only:
430 */
431
432 #if (TK_VERSION_NUMBER < _VERSION(8,4,0))
433 int wmTracing; /* Used to enable or disable tracing in
434 * this module. If tracing is enabled,
435 * then information is printed on
436 * standard output about interesting
437 * interactions with the window manager. */
438 #endif
439 struct TkWmInfo *firstWmPtr; /* Points to first top-level window. */
440 struct TkWmInfo *foregroundWmPtr;
441 /* Points to the foreground window. */
442
443 /*
444 * Information maintained by tkWindow.c for use later on by tkXId.c:
445 */
446
447
448 int destroyCount; /* Number of Tk_DestroyWindow operations
449 * in progress. */
450 unsigned long lastDestroyRequest;
451 /* Id of most recent XDestroyWindow request;
452 * can re-use ids in windowStackPtr when
453 * server has seen this request and event
454 * queue is empty. */
455
456 /*
457 * Information used by tkVisual.c only:
458 */
459
460 TkColormap *cmapPtr; /* First in list of all non-default colormaps
461 * allocated for this display. */
462
463 /*
464 * Miscellaneous information:
465 */
466
467 #ifdef TK_USE_INPUT_METHODS
468 XIM inputMethod; /* Input method for this display */
469 XIMStyle inputStyle; /* Input style selected for this display. */
470 #if (TK_VERSION_NUMBER >= _VERSION(8,4,0))
471 #if TK_XIM_SPOT
472 XFontSet inputXfs; /* XFontSet cached for over-the-spot XIM. */
473 #endif /* TK_XIM_SPOT */
474 #endif /* TK_VERSION_NUMBER >= 8.4 */
475 #endif /* TK_USE_INPUT_METHODS */
476 Tcl_HashTable winTable; /* Maps from X window ids to TkWindow ptrs. */
477 int refCount; /* Reference count of how many Tk applications
478 * are using this display. Used to clean up
479 * the display when we no longer have any
480 * Tk applications using it.
481 */
482 /*
483 * The following field were all added for Tk8.3
484 */
485 int mouseButtonState; /* current mouse button state for this
486 * display */
487 Window mouseButtonWindow; /* Window the button state was set in, added
488 * in Tk 8.4. */
489 #if (TK_VERSION_NUMBER < _VERSION(8,4,0))
490 int warpInProgress;
491 #endif
492 Window warpWindow;
493 int warpX;
494 int warpY;
495 #if (TK_VERSION_NUMBER < _VERSION(8,4,0))
496 int useInputMethods; /* Whether to use input methods */
497 #else
498 /*
499 * The following field(s) were all added for Tk8.4
500 */
501 /* long deletionEpoch; * Incremented by window deletions */
502 unsigned int flags; /* Various flag values: these are all
503 * defined in below. */
504 TkCaret caret; /* information about the caret for this
505 * display. This is not a pointer. */
506
507 int iconDataSize; /* Size of default iconphoto image data. */
508 unsigned char *iconDataPtr; /* Default iconphoto image data, if set. */
509
510 #endif
511 } TkDisplay;
512
513 #else
514
515 /*
516 * One of the following structures is maintained for each display
517 * containing a window managed by Tk:
518 */
519 typedef struct TkDisplayStruct {
520 Display *display; /* Xlib's info about display. */
521 struct TkDisplayStruct *nextPtr; /* Next in list of all displays. */
522 char *name; /* Name of display (with any screen
523 * identifier removed). Malloc-ed. */
524 Time lastEventTime; /* Time of last event received for this
525 * display. */
526
527 /*
528 * Information used primarily by tkBind.c:
529 */
530
531 int bindInfoStale; /* Non-zero means the variables in this
532 * part of the structure are potentially
533 * incorrect and should be recomputed. */
534 unsigned int modeModMask; /* Has one bit set to indicate the modifier
535 * corresponding to "mode shift". If no
536 * such modifier, than this is zero. */
537 unsigned int metaModMask; /* Has one bit set to indicate the modifier
538 * corresponding to the "Meta" key. If no
539 * such modifier, then this is zero. */
540 unsigned int altModMask; /* Has one bit set to indicate the modifier
541 * corresponding to the "Meta" key. If no
542 * such modifier, then this is zero. */
543 enum {
544 LU_IGNORE, LU_CAPS, LU_SHIFT
545 } lockUsage;
546 /* Indicates how to interpret lock modifier. */
547 int numModKeyCodes; /* Number of entries in modKeyCodes array
548 * below. */
549 KeyCode *modKeyCodes; /* Pointer to an array giving keycodes for
550 * all of the keys that have modifiers
551 * associated with them. Malloc'ed, but
552 * may be NULL. */
553
554 /*
555 * Information used by tkError.c only:
556 */
557
558 TkErrorHandler *errorPtr;
559 /* First in list of error handlers
560 * for this display. NULL means
561 * no handlers exist at present. */
562 int deleteCount; /* Counts # of handlers deleted since
563 * last time inactive handlers were
564 * garbage-collected. When this number
565 * gets big, handlers get cleaned up. */
566
567 /*
568 * Information used by tkSend.c only:
569 */
570
571 Tk_Window commTkwin; /* Window used for communication
572 * between interpreters during "send"
573 * commands. NULL means send info hasn't
574 * been initialized yet. */
575 Atom commProperty; /* X's name for comm property. */
576 Atom registryProperty; /* X's name for property containing
577 * registry of interpreter names. */
578 Atom appNameProperty; /* X's name for property used to hold the
579 * application name on each comm window. */
580
581 /*
582 * Information used by tkSelect.c and tkClipboard.c only:
583 */
584
585 TkSelectionInfo *selectionInfoPtr;
586 /* First in list of selection information
587 * records. Each entry contains information
588 * about the current owner of a particular
589 * selection on this display. */
590 Atom multipleAtom; /* Atom for MULTIPLE. None means
591 * selection stuff isn't initialized. */
592 Atom incrAtom; /* Atom for INCR. */
593 Atom targetsAtom; /* Atom for TARGETS. */
594 Atom timestampAtom; /* Atom for TIMESTAMP. */
595 Atom textAtom; /* Atom for TEXT. */
596 Atom compoundTextAtom; /* Atom for COMPOUND_TEXT. */
597 Atom applicationAtom; /* Atom for TK_APPLICATION. */
598 Atom windowAtom; /* Atom for TK_WINDOW. */
599 Atom clipboardAtom; /* Atom for CLIPBOARD. */
600
601 Tk_Window clipWindow; /* Window used for clipboard ownership and to
602 * retrieve selections between processes. NULL
603 * means clipboard info hasn't been
604 * initialized. */
605 int clipboardActive; /* 1 means we currently own the clipboard
606 * selection, 0 means we don't. */
607 TkMainInfo *clipboardAppPtr;
608 /* Last application that owned clipboard. */
609 TkClipboardTarget *clipTargetPtr;
610 /* First in list of clipboard type information
611 * records. Each entry contains information
612 * about the buffers for a given selection
613 * target. */
614
615 /*
616 * Information used by tkAtom.c only:
617 */
618
619 int atomInit; /* 0 means stuff below hasn't been
620 * initialized yet. */
621 Tcl_HashTable nameTable; /* Maps from names to Atom's. */
622 Tcl_HashTable atomTable; /* Maps from Atom's back to names. */
623
624 /*
625 * Information used by tkCursor.c only:
626 */
627
628 Font cursorFont; /* Font to use for standard cursors.
629 * None means font not loaded yet. */
630
631 /*
632 * Information used by tkGrab.c only:
633 */
634
635 TkWindow *grabWinPtr;
636 /* Window in which the pointer is currently
637 * grabbed, or NULL if none. */
638 TkWindow *eventualGrabWinPtr;
639 /* Value that grabWinPtr will have once the
640 * grab event queue (below) has been
641 * completely emptied. */
642 TkWindow *buttonWinPtr;
643 /* Window in which first mouse button was
644 * pressed while grab was in effect, or NULL
645 * if no such press in effect. */
646 TkWindow *serverWinPtr;
647 /* If no application contains the pointer then
648 * this is NULL. Otherwise it contains the
649 * last window for which we've gotten an
650 * Enter or Leave event from the server (i.e.
651 * the last window known to have contained
652 * the pointer). Doesn't reflect events
653 * that were synthesized in tkGrab.c. */
654 TkGrabEvent *firstGrabEventPtr;
655 /* First in list of enter/leave events
656 * synthesized by grab code. These events
657 * must be processed in order before any other
658 * events are processed. NULL means no such
659 * events. */
660 TkGrabEvent *lastGrabEventPtr;
661 /* Last in list of synthesized events, or NULL
662 * if list is empty. */
663 int grabFlags; /* Miscellaneous flag values. See definitions
664 * in tkGrab.c. */
665
666 /*
667 * Information used by tkXId.c only:
668 */
669
670 TkIdStack *idStackPtr;
671 /* First in list of chunks of free resource
672 * identifiers, or NULL if there are no free
673 * resources. */
674 XID(*defaultAllocProc) _ANSI_ARGS_((Display *display));
675 /* Default resource allocator for display. */
676 TkIdStack *windowStackPtr;
677 /* First in list of chunks of window
678 * identifers that can't be reused right
679 * now. */
680 int idCleanupScheduled; /* 1 means a call to WindowIdCleanup has
681 * already been scheduled, 0 means it
682 * hasn't. */
683
684 /*
685 * Information maintained by tkWindow.c for use later on by tkXId.c:
686 */
687
688
689 int destroyCount; /* Number of Tk_DestroyWindow operations
690 * in progress. */
691 unsigned long lastDestroyRequest;
692 /* Id of most recent XDestroyWindow request;
693 * can re-use ids in windowStackPtr when
694 * server has seen this request and event
695 * queue is empty. */
696
697 /*
698 * Information used by tkVisual.c only:
699 */
700
701 TkColormap *cmapPtr; /* First in list of all non-default colormaps
702 * allocated for this display. */
703
704 /*
705 * Information used by tkFocus.c only:
706 */
707 #if (TK_MAJOR_VERSION == 4)
708
709 TkWindow *focusWinPtr;
710 /* Window that currently has the focus for
711 * this display, or NULL if none. */
712 TkWindow *implicitWinPtr;
713 /* If the focus arrived at a toplevel window
714 * implicitly via an Enter event (rather
715 * than via a FocusIn event), this points
716 * to the toplevel window. Otherwise it is
717 * NULL. */
718 TkWindow *focusOnMapPtr;
719 /* This points to a toplevel window that is
720 * supposed to receive the X input focus as
721 * soon as it is mapped (needed to handle the
722 * fact that X won't allow the focus on an
723 * unmapped window). NULL means no delayed
724 * focus op in progress. */
725 int forceFocus; /* Associated with focusOnMapPtr: non-zero
726 * means claim the focus even if some other
727 * application currently has it. */
728 #else
729 TkWindow *implicitWinPtr;
730 /* If the focus arrived at a toplevel window
731 * implicitly via an Enter event (rather
732 * than via a FocusIn event), this points
733 * to the toplevel window. Otherwise it is
734 * NULL. */
735 TkWindow *focusPtr; /* Points to the window on this display that
736 * should be receiving keyboard events. When
737 * multiple applications on the display have
738 * the focus, this will refer to the
739 * innermost window in the innermost
740 * application. This information isn't used
741 * under Unix or Windows, but it's needed on
742 * the Macintosh. */
743 #endif /* TK_MAJOR_VERSION == 4 */
744
745 /*
746 * Used by tkColor.c only:
747 */
748
749 TkStressedCmap *stressPtr; /* First in list of colormaps that have
750 * filled up, so we have to pick an
751 * approximate color. */
752
753 /*
754 * Used by tkEvent.c only:
755 */
756
757 TkWindowEvent *delayedMotionPtr;
758 /* Points to a malloc-ed motion event
759 * whose processing has been delayed in
760 * the hopes that another motion event
761 * will come along right away and we can
762 * merge the two of them together. NULL
763 * means that there is no delayed motion
764 * event. */
765 /*
766 * Miscellaneous information:
767 */
768
769 #ifdef TK_USE_INPUT_METHODS
770 XIM inputMethod; /* Input method for this display */
771 #endif /* TK_USE_INPUT_METHODS */
772 Tcl_HashTable winTable; /* Maps from X window ids to TkWindow ptrs. */
773 #if (TK_MAJOR_VERSION > 4)
774 int refCount; /* Reference count of how many Tk applications
775 * are using this display. Used to clean up
776 * the display when we no longer have any
777 * Tk applications using it.
778 */
779 #endif /* TK_MAJOR_VERSION > 4 */
780
781 } TkDisplay;
782
783 #endif /* TK_VERSION_NUMBER >= _VERSION(8,1,0) */
784
785
786 struct TkWindowStruct {
787 Display *display;
788 TkDisplay *dispPtr;
789 int screenNum;
790 Visual *visual;
791 int depth;
792 Window window;
793 TkWindow *childList;
794 TkWindow *lastChildPtr;
795 TkWindow *parentPtr;
796 TkWindow *nextPtr;
797 TkMainInfo *infoPtr;
798 char *pathName;
799 Tk_Uid nameUid;
800 Tk_Uid classUid;
801 XWindowChanges changes;
802 unsigned int dirtyChanges;
803 XSetWindowAttributes atts;
804 unsigned long dirtyAtts;
805 unsigned int flags;
806 TkEventHandler *handlerList;
807 #ifdef TK_USE_INPUT_METHODS
808 XIC inputContext;
809 #endif /* TK_USE_INPUT_METHODS */
810 ClientData *tagPtr;
811 int nTags;
812 int optionLevel;
813 TkSelHandler *selHandlerList;
814 Tk_GeomMgr *geomMgrPtr;
815 ClientData geomData;
816 int reqWidth, reqHeight;
817 int internalBorderWidth;
818 TkWinInfo *wmInfoPtr;
819 #if (TK_MAJOR_VERSION > 4)
820 TkClassProcs *classProcsPtr;
821 ClientData instanceData;
822 #endif
823 TkWindowPrivate *privatePtr;
824 int internalBorderRight;
825 int internalBorderTop;
826 int internalBorderBottom;
827
828 int minReqWidth;
829 int minReqHeight;
830
831 };
832
833 #ifdef WIN32
834 /*
835 *----------------------------------------------------------------------
836 *
837 * GetWindowHandle --
838 *
839 * Returns the XID for the Tk_Window given. Starting in Tk 8.0,
840 * the toplevel widgets are wrapped by another window.
841 * Currently there's no way to get at that window, other than
842 * what is done here: query the X window hierarchy and grab the
843 * parent.
844 *
845 * Results:
846 * Returns the X Window ID of the widget. If it's a toplevel, then
847 * the XID of the wrapper is returned.
848 *
849 *----------------------------------------------------------------------
850 */
851 static HWND
852 GetWindowHandle(Tk_Window tkwin)
853 {
854 HWND hWnd;
855 Window window;
856
857 window = Tk_WindowId(tkwin);
858 if (window == None) {
859 Tk_MakeWindowExist(tkwin);
860 }
861 hWnd = Tk_GetHWND(Tk_WindowId(tkwin));
862 #if (TK_MAJOR_VERSION > 4)
863 if (Tk_IsTopLevel(tkwin)) {
864 hWnd = GetParent(hWnd);
865 }
866 #endif /* TK_MAJOR_VERSION > 4 */
867 return hWnd;
868 }
869
870 Window
871 Blt_GetParent(display, window)
872 Display *display;
873 Window window;
874 {
875 HWND hWnd;
876 hWnd = GetWindowHandle(window);
877 return (Window)hWnd;
878 }
879
880 #else
881
882 Window
883 Blt_GetParent(display, window)
884 Display *display;
885 Window window;
886 {
887 Window root, parent;
888 Window *dummy;
889 unsigned int count;
890
891 if (XQueryTree(display, window, &root, &parent, &dummy, &count) > 0) {
892 XFree(dummy);
893 return parent;
894 }
895 return None;
896 }
897
898 static Window
899 GetWindowId(tkwin)
900 Tk_Window tkwin;
901 {
902 Window window;
903
904 Tk_MakeWindowExist(tkwin);
905 window = Tk_WindowId(tkwin);
906 #if (TK_MAJOR_VERSION > 4)
907 if (Tk_IsTopLevel(tkwin)) {
908 Window parent;
909
910 parent = Blt_GetParent(Tk_Display(tkwin), window);
911 if (parent != None && parent != XRootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin))) {
912 window = parent;
913 }
914 /*window = parent; */
915 }
916 #endif /* TK_MAJOR_VERSION > 4 */
917 return window;
918 }
919
920 #endif /* WIN32 */
921
922 /*
923 *----------------------------------------------------------------------
924 *
925 * DoConfigureNotify --
926 *
927 * Generate a ConfigureNotify event describing the current
928 * configuration of a window.
929 *
930 * Results:
931 * None.
932 *
933 * Side effects:
934 * An event is generated and processed by Tk_HandleEvent.
935 *
936 *----------------------------------------------------------------------
937 */
938 static void
939 DoConfigureNotify(winPtr)
940 Tk_FakeWin *winPtr; /* Window whose configuration was just
941 * changed. */
942 {
943 XEvent event;
944
945 event.type = ConfigureNotify;
946 event.xconfigure.serial = LastKnownRequestProcessed(winPtr->display);
947 event.xconfigure.send_event = False;
948 event.xconfigure.display = winPtr->display;
949 event.xconfigure.event = winPtr->window;
950 event.xconfigure.window = winPtr->window;
951 event.xconfigure.x = winPtr->changes.x;
952 event.xconfigure.y = winPtr->changes.y;
953 event.xconfigure.width = winPtr->changes.width;
954 event.xconfigure.height = winPtr->changes.height;
955 event.xconfigure.border_width = winPtr->changes.border_width;
956 if (winPtr->changes.stack_mode == Above) {
957 event.xconfigure.above = winPtr->changes.sibling;
958 } else {
959 event.xconfigure.above = None;
960 }
961 event.xconfigure.override_redirect = winPtr->atts.override_redirect;
962 Tk_HandleEvent(&event);
963 }
964
965 /*
966 *--------------------------------------------------------------
967 *
968 * Blt_MakeTransparentWindowExist --
969 *
970 * Similar to Tk_MakeWindowExist but instead creates a
971 * transparent window to block for user events from sibling
972 * windows.
973 *
974 * Differences from Tk_MakeWindowExist.
975 *
976 * 1. This is always a "busy" window. There's never a
977 * platform-specific class procedure to execute instead.
978 * 2. The window is transparent and never will contain children,
979 * so colormap information is irrelevant.
980 *
981 * Results:
982 * None.
983 *
984 * Side effects:
985 * When the procedure returns, the internal window associated
986 * with tkwin is guaranteed to exist. This may require the
987 * window's ancestors to be created too.
988 *
989 *--------------------------------------------------------------
990 */
991 void
992 Blt_MakeTransparentWindowExist(tkwin, parent, isBusy)
993 Tk_Window tkwin; /* Token for window. */
994 Window parent; /* Parent window. */
995 int isBusy; /* */
996 {
997 TkWindow *winPtr = (TkWindow *) tkwin;
998 TkWindow *winPtr2;
999 Tcl_HashEntry *hPtr;
1000 int notUsed;
1001 TkDisplay *dispPtr;
1002 #ifdef WIN32
1003 HWND hParent;
1004 int style;
1005 DWORD exStyle;
1006 HWND hWnd;
1007 #else
1008 long int mask;
1009 #endif /* WIN32 */
1010
1011 if (winPtr->window != None) {
1012 return; /* Window already exists. */
1013 }
1014 #ifdef notdef
1015 if ((winPtr->parentPtr == NULL) || (winPtr->flags & TK_TOP_LEVEL)) {
1016 parent = XRootWindow(winPtr->display, winPtr->screenNum);
1017 /* TODO: Make the entire screen busy */
1018 } else {
1019 if (Tk_WindowId(winPtr->parentPtr) == None) {
1020 Tk_MakeWindowExist((Tk_Window)winPtr->parentPtr);
1021 }
1022 }
1023 #endif
1024
1025 /* Create a transparent window and put it on top. */
1026
1027 #ifdef WIN32
1028 hParent = (HWND) parent;
1029 style = (WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
1030 exStyle = (WS_EX_TRANSPARENT | WS_EX_TOPMOST);
1031 #define TK_WIN_CHILD_CLASS_NAME "TkChild"
1032 hWnd = CreateWindowEx(exStyle, TK_WIN_CHILD_CLASS_NAME, NULL, style,
1033 Tk_X(tkwin), Tk_Y(tkwin), Tk_Width(tkwin), Tk_Height(tkwin),
1034 hParent, NULL, (HINSTANCE) Tk_GetHINSTANCE(), NULL);
1035 winPtr->window = Tk_AttachHWND(tkwin, hWnd);
1036 #else
1037 mask = (!isBusy) ? 0 : (CWDontPropagate | CWEventMask);
1038 /* Ignore the important events while the window is mapped. */
1039 #define USER_EVENTS (EnterWindowMask | LeaveWindowMask | KeyPressMask | \
1040 KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
1041 #define PROP_EVENTS (KeyPressMask | KeyReleaseMask | ButtonPressMask | \
1042 ButtonReleaseMask | PointerMotionMask)
1043
1044 winPtr->atts.do_not_propagate_mask = PROP_EVENTS;
1045 winPtr->atts.event_mask = USER_EVENTS;
1046 winPtr->changes.border_width = 0;
1047 winPtr->depth = 0;
1048
1049 winPtr->window = XCreateWindow(winPtr->display, parent,
1050 winPtr->changes.x, winPtr->changes.y,
1051 (unsigned)winPtr->changes.width, /* width */
1052 (unsigned)winPtr->changes.height, /* height */
1053 (unsigned)winPtr->changes.border_width, /* border_width */
1054 winPtr->depth, /* depth */
1055 InputOnly, /* class */
1056 winPtr->visual, /* visual */
1057 mask, /* valuemask */
1058 &(winPtr->atts) /* attributes */ );
1059 #endif /* WIN32 */
1060
1061 dispPtr = winPtr->dispPtr;
1062 hPtr = Tcl_CreateHashEntry(&(dispPtr->winTable), (char *)winPtr->window,
1063 &notUsed);
1064 Tcl_SetHashValue(hPtr, winPtr);
1065 winPtr->dirtyAtts = 0;
1066 winPtr->dirtyChanges = 0;
1067 #ifdef TK_USE_INPUT_METHODS
1068 winPtr->inputContext = NULL;
1069 #endif /* TK_USE_INPUT_METHODS */
1070 if (!(winPtr->flags & TK_TOP_LEVEL)) {
1071 /*
1072 * If any siblings higher up in the stacking order have already
1073 * been created then move this window to its rightful position
1074 * in the stacking order.
1075 *
1076 * NOTE: this code ignores any changes anyone might have made
1077 * to the sibling and stack_mode field of the window's attributes,
1078 * so it really isn't safe for these to be manipulated except
1079 * by calling Tk_RestackWindow.
1080 */
1081 for (winPtr2 = winPtr->nextPtr; winPtr2 != NULL;
1082 winPtr2 = winPtr2->nextPtr) {
1083 if ((winPtr2->window != None) && !(winPtr2->flags & TK_TOP_LEVEL)) {
1084 XWindowChanges changes;
1085 changes.sibling = winPtr2->window;
1086 changes.stack_mode = Below;
1087 XConfigureWindow(winPtr->display, winPtr->window,
1088 CWSibling | CWStackMode, &changes);
1089 break;
1090 }
1091 }
1092 }
1093
1094 /*
1095 * Issue a ConfigureNotify event if there were deferred configuration
1096 * changes (but skip it if the window is being deleted; the
1097 * ConfigureNotify event could cause problems if we're being called
1098 * from Tk_DestroyWindow under some conditions).
1099 */
1100 if ((winPtr->flags & TK_NEED_CONFIG_NOTIFY)
1101 && !(winPtr->flags & TK_ALREADY_DEAD)) {
1102 winPtr->flags &= ~TK_NEED_CONFIG_NOTIFY;
1103 DoConfigureNotify((Tk_FakeWin *) tkwin);
1104 }
1105 }
1106
1107 /*
1108 *----------------------------------------------------------------------
1109 *
1110 * Blt_FindChild --
1111 *
1112 * Performs a linear search for the named child window in a given
1113 * parent window.
1114 *
1115 * This can be done via Tcl, but not through Tk's C API. It's
1116 * simple enough, if you peek into the Tk_Window structure.
1117 *
1118 * Results:
1119 * The child Tk_Window. If the named child can't be found, NULL
1120 * is returned.
1121 *
1122 *----------------------------------------------------------------------
1123 */
1124
1125 /*LINTLIBRARY*/
1126 Tk_Window
1127 Blt_FindChild(parent, name)
1128 Tk_Window parent;
1129 char *name;
1130 {
1131 register TkWindow *winPtr;
1132 TkWindow *parentPtr = (TkWindow *)parent;
1133
1134 for (winPtr = parentPtr->childList; winPtr != NULL;
1135 winPtr = winPtr->nextPtr) {
1136 if (strcmp(name, winPtr->nameUid) == 0) {
1137 return (Tk_Window)winPtr;
1138 }
1139 }
1140 return NULL;
1141 }
1142
1143 /*
1144 *----------------------------------------------------------------------
1145 *
1146 * Blt_FirstChildWindow --
1147 *
1148 * Performs a linear search for the named child window in a given
1149 * parent window.
1150 *
1151 * This can be done via Tcl, but not through Tk's C API. It's
1152 * simple enough, if you peek into the Tk_Window structure.
1153 *
1154 * Results:
1155 * The child Tk_Window. If the named child can't be found, NULL
1156 * is returned.
1157 *
1158 *----------------------------------------------------------------------
1159 */
1160 /*LINTLIBRARY*/
1161 Tk_Window
1162 Blt_FirstChild(parent)
1163 Tk_Window parent;
1164 {
1165 TkWindow *parentPtr = (TkWindow *)parent;
1166 return (Tk_Window)parentPtr->childList;
1167 }
1168
1169 /*
1170 *----------------------------------------------------------------------
1171 *
1172 * Blt_FindChild --
1173 *
1174 * Performs a linear search for the named child window in a given
1175 * parent window.
1176 *
1177 * This can be done via Tcl, but not through Tk's C API. It's
1178 * simple enough, if you peek into the Tk_Window structure.
1179 *
1180 * Results:
1181 * The child Tk_Window. If the named child can't be found, NULL
1182 * is returned.
1183 *
1184 *----------------------------------------------------------------------
1185 */
1186
1187 /*LINTLIBRARY*/
1188 Tk_Window
1189 Blt_NextChild(tkwin)
1190 Tk_Window tkwin;
1191 {
1192 TkWindow *winPtr = (TkWindow *)tkwin;
1193
1194 if (winPtr == NULL) {
1195 return NULL;
1196 }
1197 return (Tk_Window)winPtr->nextPtr;
1198 }
1199
1200 /*
1201 *----------------------------------------------------------------------
1202 *
1203 * UnlinkWindow --
1204 *
1205 * This procedure removes a window from the childList of its
1206 * parent.
1207 *
1208 * Results:
1209 * None.
1210 *
1211 * Side effects:
1212 * The window is unlinked from its childList.
1213 *
1214 *----------------------------------------------------------------------
1215 */
1216 static void
1217 UnlinkWindow(winPtr)
1218 TkWindow *winPtr; /* Child window to be unlinked. */
1219 {
1220 TkWindow *prevPtr;
1221
1222 prevPtr = winPtr->parentPtr->childList;
1223 if (prevPtr == winPtr) {
1224 winPtr->parentPtr->childList = winPtr->nextPtr;
1225 if (winPtr->nextPtr == NULL) {
1226 winPtr->parentPtr->lastChildPtr = NULL;
1227 }
1228 } else {
1229 while (prevPtr->nextPtr != winPtr) {
1230 prevPtr = prevPtr->nextPtr;
1231 if (prevPtr == NULL) {
1232 panic("UnlinkWindow couldn't find child in parent");
1233 }
1234 }
1235 prevPtr->nextPtr = winPtr->nextPtr;
1236 if (winPtr->nextPtr == NULL) {
1237 winPtr->parentPtr->lastChildPtr = prevPtr;
1238 }
1239 }
1240 }
1241
1242 /*
1243 *----------------------------------------------------------------------
1244 *
1245 * Blt_RelinkWindow --
1246 *
1247 * Relinks a window into a new parent. The window is unlinked
1248 * from its original parent's child list and added onto the end
1249 * of the new parent's list.
1250 *
1251 * FIXME: If the window has focus, the focus should be moved
1252 * to an ancestor. Otherwise, Tk becomes confused
1253 * about which Toplevel turns on focus for the window.
1254 * Right now this is done at the Tcl layer. For example,
1255 * see blt::CreateTearoff in tabset.tcl.
1256 *
1257 * Results:
1258 * None.
1259 *
1260 * Side effects:
1261 * The window is unlinked from its childList.
1262 *
1263 *----------------------------------------------------------------------
1264 */
1265 void
1266 Blt_RelinkWindow(tkwin, newParent, x, y)
1267 Tk_Window tkwin; /* Child window to be linked. */
1268 Tk_Window newParent;
1269 int x, y;
1270 {
1271 TkWindow *winPtr, *parentWinPtr;
1272
1273 if (Blt_ReparentWindow(Tk_Display(tkwin), Tk_WindowId(tkwin),
1274 Tk_WindowId(newParent), x, y) != TCL_OK) {
1275 return;
1276 }
1277 winPtr = (TkWindow *)tkwin;
1278 parentWinPtr = (TkWindow *)newParent;
1279
1280 winPtr->flags &= ~TK_REPARENTED;
1281 UnlinkWindow(winPtr); /* Remove the window from its parent's list */
1282
1283 /* Append the window onto the end of the parent's list of children */
1284 winPtr->parentPtr = parentWinPtr;
1285 winPtr->nextPtr = NULL;
1286 if (parentWinPtr->childList == NULL) {
1287 parentWinPtr->childList = winPtr;
1288 } else {
1289 parentWinPtr->lastChildPtr->nextPtr = winPtr;
1290 }
1291 parentWinPtr->lastChildPtr = winPtr;
1292 }
1293
1294 /*
1295 *----------------------------------------------------------------------
1296 *
1297 * Blt_RelinkWindow --
1298 *
1299 * Relinks a window into a new parent. The window is unlinked
1300 * from its original parent's child list and added onto the end
1301 * of the new parent's list.
1302 *
1303 * FIXME: If the window has focus, the focus should be moved
1304 * to an ancestor. Otherwise, Tk becomes confused
1305 * about which Toplevel turns on focus for the window.
1306 * Right now this is done at the Tcl layer. For example,
1307 * see blt::CreateTearoff in tabset.tcl.
1308 *
1309 * Results:
1310 * None.
1311 *
1312 * Side effects:
1313 * The window is unlinked from its childList.
1314 *
1315 *----------------------------------------------------------------------
1316 */
1317 void
1318 Blt_RelinkWindow2(tkwin, window, newParent, x, y)
1319 Tk_Window tkwin; /* Child window to be linked. */
1320 Window window;
1321 Tk_Window newParent;
1322 int x, y;
1323 {
1324 #ifdef notdef
1325 TkWindow *winPtr, *parentWinPtr;
1326 #endif
1327 if (Blt_ReparentWindow(Tk_Display(tkwin), window,
1328 Tk_WindowId(newParent), x, y) != TCL_OK) {
1329 return;
1330 }
1331 #ifdef notdef
1332 winPtr = (TkWindow *)tkwin;
1333 parentWinPtr = (TkWindow *)newParent;
1334
1335 winPtr->flags &= ~TK_REPARENTED;
1336 UnlinkWindow(winPtr); /* Remove the window from its parent's list */
1337
1338 /* Append the window onto the end of the parent's list of children */
1339 winPtr->parentPtr = parentWinPtr;
1340 winPtr->nextPtr = NULL;
1341 if (parentWinPtr->childList == NULL) {
1342 parentWinPtr->childList = winPtr;
1343 } else {
1344 parentWinPtr->lastChildPtr->nextPtr = winPtr;
1345 }
1346 parentWinPtr->lastChildPtr = winPtr;
1347 #endif
1348 }
1349
1350 void
1351 Blt_UnlinkWindow(tkwin)
1352 Tk_Window tkwin; /* Child window to be linked. */
1353 {
1354 TkWindow *winPtr;
1355 Window root;
1356
1357 root = XRootWindow(Tk_Display(tkwin), Tk_ScreenNumber(tkwin));
1358 if (Blt_ReparentWindow(Tk_Display(tkwin), Tk_WindowId(tkwin),
1359 root, 0, 0) != TCL_OK) {
1360 return;
1361 }
1362 winPtr = (TkWindow *)tkwin;
1363 winPtr->flags &= ~TK_REPARENTED;
1364 #ifdef notdef
1365 UnlinkWindow(winPtr); /* Remove the window from its parent's list */
1366 #endif
1367 }
1368
1369 /*
1370 *----------------------------------------------------------------------
1371 *
1372 * Blt_Toplevel --
1373 *
1374 * Climbs up the widget hierarchy to find the top level window of
1375 * the window given.
1376 *
1377 * Results:
1378 * Returns the Tk_Window of the toplevel widget.
1379 *
1380 *----------------------------------------------------------------------
1381 */
1382 Tk_Window
1383 Blt_Toplevel(tkwin)
1384 register Tk_Window tkwin;
1385 {
1386 while (!Tk_IsTopLevel(tkwin)) {
1387 tkwin = Tk_Parent(tkwin);
1388 }
1389 return tkwin;
1390 }
1391
1392 void
1393 Blt_RootCoordinates(tkwin, x, y, rootXPtr, rootYPtr)
1394 Tk_Window tkwin;
1395 int x, y;
1396 int *rootXPtr, *rootYPtr;
1397 {
1398 int vx, vy, vw, vh;
1399 int rootX, rootY;
1400
1401 Tk_GetRootCoords(tkwin, &rootX, &rootY);
1402 x += rootX;
1403 y += rootY;
1404 Tk_GetVRootGeometry(tkwin, &vx, &vy, &vw, &vh);
1405 x += vx;
1406 y += vy;
1407 *rootXPtr = x;
1408 *rootYPtr = y;
1409 }
1410
1411
1412 /* Find the toplevel then */
1413 int
1414 Blt_RootX(tkwin)
1415 Tk_Window tkwin;
1416 {
1417 int x;
1418
1419 for (x = 0; tkwin != NULL; tkwin = Tk_Parent(tkwin)) {
1420 x += Tk_X(tkwin) + Tk_Changes(tkwin)->border_width;
1421 if (Tk_IsTopLevel(tkwin)) {
1422 break;
1423 }
1424 }
1425 return x;
1426 }
1427
1428 int
1429 Blt_RootY(tkwin)
1430 Tk_Window tkwin;
1431 {
1432 int y;
1433
1434 for (y = 0; tkwin != NULL; tkwin = Tk_Parent(tkwin)) {
1435 y += Tk_Y(tkwin) + Tk_Changes(tkwin)->border_width;
1436 if (Tk_IsTopLevel(tkwin)) {
1437 break;
1438 }
1439 }
1440 return y;
1441 }
1442
1443 #ifdef WIN32
1444 /*
1445 *----------------------------------------------------------------------
1446 *
1447 * Blt_GetRealWindowId --
1448 *
1449 * Returns the XID for the Tk_Window given. Starting in Tk 8.0,
1450 * the toplevel widgets are wrapped by another window.
1451 * Currently there's no way to get at that window, other than
1452 * what is done here: query the X window hierarchy and grab the
1453 * parent.
1454 *
1455 * Results:
1456 * Returns the X Window ID of the widget. If it's a toplevel, then
1457 * the XID of the wrapper is returned.
1458 *
1459 *----------------------------------------------------------------------
1460 */
1461 Window
1462 Blt_GetRealWindowId(Tk_Window tkwin)
1463 {
1464 return (Window) GetWindowHandle(tkwin);
1465 }
1466
1467 /*
1468 *----------------------------------------------------------------------
1469 *
1470 * Blt_GetToplevel --
1471 *
1472 * Retrieves the toplevel window which is the nearest ancestor of
1473 * of the specified window.
1474 *
1475 * Results:
1476 * Returns the toplevel window or NULL if the window has no
1477 * ancestor which is a toplevel.
1478 *
1479 * Side effects:
1480 * None.
1481 *
1482 *----------------------------------------------------------------------
1483 */
1484 Tk_Window
1485 Blt_GetToplevel(Tk_Window tkwin) /* Window for which the toplevel
1486 * should be deterined. */
1487 {
1488 while (!Tk_IsTopLevel(tkwin)) {
1489 tkwin = Tk_Parent(tkwin);
1490 if (tkwin == NULL) {
1491 return NULL;
1492 }
1493 }
1494 return tkwin;
1495 }
1496
1497 /*
1498 *----------------------------------------------------------------------
1499 *
1500 * Blt_RaiseToLevelWindow --
1501 *
1502 * Results:
1503 * None.
1504 *
1505 *----------------------------------------------------------------------
1506 */
1507 void
1508 Blt_RaiseToplevel(Tk_Window tkwin)
1509 {
1510 SetWindowPos(GetWindowHandle(tkwin), HWND_TOP, 0, 0, 0, 0,
1511 SWP_NOMOVE | SWP_NOSIZE);
1512 }
1513
1514 /*
1515 *----------------------------------------------------------------------
1516 *
1517 * Blt_MapToplevel --
1518 *
1519 * Results:
1520 * None.
1521 *
1522 *----------------------------------------------------------------------
1523 */
1524 void
1525 Blt_MapToplevel(Tk_Window tkwin)
1526 {
1527 ShowWindow(GetWindowHandle(tkwin), SW_SHOWNORMAL);
1528 }
1529
1530 /*
1531 *----------------------------------------------------------------------
1532 *
1533 * Blt_UnmapToplevel --
1534 *
1535 * Results:
1536 * None.
1537 *
1538 *----------------------------------------------------------------------
1539 */
1540 void
1541 Blt_UnmapToplevel(Tk_Window tkwin)
1542 {
1543 ShowWindow(GetWindowHandle(tkwin), SW_HIDE);
1544 }
1545
1546 /*
1547 *----------------------------------------------------------------------
1548 *
1549 * Blt_MoveResizeToplevel --
1550 *
1551 * Results:
1552 * None.
1553 *
1554 *----------------------------------------------------------------------
1555 */
1556 void
1557 Blt_MoveResizeToplevel(tkwin, x, y, width, height)
1558 Tk_Window tkwin;
1559 int x, y, width, height;
1560 {
1561 SetWindowPos(GetWindowHandle(tkwin), HWND_TOP, x, y, width, height, 0);
1562 }
1563
1564 int
1565 Blt_ReparentWindow(
1566 Display *display,
1567 Window window,
1568 Window newParent,
1569 int x, int y)
1570 {
1571 XReparentWindow(display, window, newParent, x, y);
1572 return TCL_OK;
1573 }
1574
1575 #else /* WIN32 */
1576
1577 /*
1578 *----------------------------------------------------------------------
1579 *
1580 * Blt_GetRealWindowId --
1581 *
1582 * Returns the XID for the Tk_Window given. Starting in Tk 8.0,
1583 * the toplevel widgets are wrapped by another window.
1584 * Currently there's no way to get at that window, other than
1585 * what is done here: query the X window hierarchy and grab the
1586 * parent.
1587 *
1588 * Results:
1589 * Returns the X Window ID of the widget. If it's a toplevel, then
1590 * the XID of the wrapper is returned.
1591 *
1592 *----------------------------------------------------------------------
1593 */
1594 Window
1595 Blt_GetRealWindowId(tkwin)
1596 Tk_Window tkwin;
1597 {
1598 return GetWindowId(tkwin);
1599 }
1600
1601 /*
1602 *----------------------------------------------------------------------
1603 *
1604 * Blt_RaiseToplevel --
1605 *
1606 * Results:
1607 * None.
1608 *
1609 *----------------------------------------------------------------------
1610 */
1611 void
1612 Blt_RaiseToplevel(tkwin)
1613 Tk_Window tkwin;
1614 {
1615 XRaiseWindow(Tk_Display(tkwin), GetWindowId(tkwin));
1616 }
1617
1618 /*
1619 *----------------------------------------------------------------------
1620 *
1621 * Blt_LowerToplevel --
1622 *
1623 * Results:
1624 * None.
1625 *
1626 *----------------------------------------------------------------------
1627 */
1628 void
1629 Blt_LowerToplevel(tkwin)
1630 Tk_Window tkwin;
1631 {
1632 XLowerWindow(Tk_Display(tkwin), GetWindowId(tkwin));
1633 }
1634
1635 /*
1636 *----------------------------------------------------------------------
1637 *
1638 * Blt_ResizeToplevel --
1639 *
1640 * Results:
1641 * None.
1642 *
1643 *----------------------------------------------------------------------
1644 */
1645 void
1646 Blt_ResizeToplevel(tkwin, width, height)
1647 Tk_Window tkwin;
1648 int width, height;
1649 {
1650 XResizeWindow(Tk_Display(tkwin), GetWindowId(tkwin), width, height);
1651 }
1652
1653 /*
1654 *----------------------------------------------------------------------
1655 *
1656 * Blt_MoveResizeToplevel --
1657 *
1658 * Results:
1659 * None.
1660 *
1661 *----------------------------------------------------------------------
1662 */
1663 void
1664 Blt_MoveResizeToplevel(tkwin, x, y, width, height)
1665 Tk_Window tkwin;
1666 int x, y, width, height;
1667 {
1668 XMoveResizeWindow(Tk_Display(tkwin), GetWindowId(tkwin), x, y,
1669 width, height);
1670 }
1671
1672 /*
1673 *----------------------------------------------------------------------
1674 *
1675 * Blt_ResizeToplevel --
1676 *
1677 * Results:
1678 * None.
1679 *
1680 *----------------------------------------------------------------------
1681 */
1682 void
1683 Blt_MoveToplevel(tkwin, x, y)
1684 Tk_Window tkwin;
1685 int x, y;
1686 {
1687 XMoveWindow(Tk_Display(tkwin), GetWindowId(tkwin), x, y);
1688 }
1689
1690 /*
1691 *----------------------------------------------------------------------
1692 *
1693 * Blt_MapToplevel --
1694 *
1695 * Results:
1696 * None.
1697 *
1698 *----------------------------------------------------------------------
1699 */
1700 void
1701 Blt_MapToplevel(tkwin)
1702 Tk_Window tkwin;
1703 {
1704 XMapWindow(Tk_Display(tkwin), GetWindowId(tkwin));
1705 }
1706
1707 /*
1708 *----------------------------------------------------------------------
1709 *
1710 * Blt_UnmapToplevel --
1711 *
1712 * Results:
1713 * None.
1714 *
1715 *----------------------------------------------------------------------
1716 */
1717 void
1718 Blt_UnmapToplevel(tkwin)
1719 Tk_Window tkwin;
1720 {
1721 XUnmapWindow(Tk_Display(tkwin), GetWindowId(tkwin));
1722 }
1723
1724 /* ARGSUSED */
1725 static int
1726 XReparentWindowErrorProc(clientData, errEventPtr)
1727 ClientData clientData;
1728 XErrorEvent *errEventPtr;
1729 {
1730 int *errorPtr = clientData;
1731
1732 *errorPtr = TCL_ERROR;
1733 return 0;
1734 }
1735
1736 int
1737 Blt_ReparentWindow(display, window, newParent, x, y)
1738 Display *display;
1739 Window window, newParent;
1740 int x, y;
1741 {
1742 Tk_ErrorHandler handler;
1743 int result;
1744 int any = -1;
1745
1746 result = TCL_OK;
1747 handler = Tk_CreateErrorHandler(display, any, X_ReparentWindow, any,
1748 XReparentWindowErrorProc, &result);
1749 XReparentWindow(display, window, newParent, x, y);
1750 Tk_DeleteErrorHandler(handler);
1751 XSync(display, False);
1752 return result;
1753 }
1754
1755 #endif /* WIN32 */
1756
1757 #if (TK_MAJOR_VERSION == 4)
1758 #include <bltHash.h>
1759 static int initialized = FALSE;
1760 static Blt_HashTable windowTable;
1761
1762 void
1763 Blt_SetWindowInstanceData(tkwin, instanceData)
1764 Tk_Window tkwin;
1765 ClientData instanceData;
1766 {
1767 Blt_HashEntry *hPtr;
1768 int isNew;
1769
1770 if (!initialized) {
1771 Blt_InitHashTable(&windowTable, BLT_ONE_WORD_KEYS);
1772 initialized = TRUE;
1773 }
1774 hPtr = Blt_CreateHashEntry(&windowTable, (char *)tkwin, &isNew);
1775 assert(isNew);
1776 Blt_SetHashValue(hPtr, instanceData);
1777 }
1778
1779 ClientData
1780 Blt_GetWindowInstanceData(tkwin)
1781 Tk_Window tkwin;
1782 {
1783 Blt_HashEntry *hPtr;
1784
1785 hPtr = Blt_FindHashEntry(&windowTable, (char *)tkwin);
1786 if (hPtr == NULL) {
1787 return NULL;
1788 }
1789 return Blt_GetHashValue(hPtr);
1790 }
1791
1792 void
1793 Blt_DeleteWindowInstanceData(tkwin)
1794 Tk_Window tkwin;
1795 {
1796 Blt_HashEntry *hPtr;
1797
1798 hPtr = Blt_FindHashEntry(&windowTable, (char *)tkwin);
1799 assert(hPtr);
1800 Blt_DeleteHashEntry(&windowTable, hPtr);
1801 }
1802
1803 #else
1804
1805 void
1806 Blt_SetWindowInstanceData(tkwin, instanceData)
1807 Tk_Window tkwin;
1808 ClientData instanceData;
1809 {
1810 TkWindow *winPtr = (TkWindow *)tkwin;
1811
1812 winPtr->instanceData = instanceData;
1813 }
1814
1815 ClientData
1816 Blt_GetWindowInstanceData(tkwin)
1817 Tk_Window tkwin;
1818 {
1819 TkWindow *winPtr = (TkWindow *)tkwin;
1820
1821 return winPtr->instanceData;
1822 }
1823
1824 void
1825 Blt_DeleteWindowInstanceData(tkwin)
1826 Tk_Window tkwin;
1827 {
1828 }
1829
1830 #endif
1831