summaryrefslogtreecommitdiffstats
path: root/mac/tkMacXCursors.r
diff options
context:
space:
mode:
Diffstat (limited to 'mac/tkMacXCursors.r')
-rw-r--r--mac/tkMacXCursors.r961
1 files changed, 0 insertions, 961 deletions
diff --git a/mac/tkMacXCursors.r b/mac/tkMacXCursors.r
deleted file mode 100644
index f04def6..0000000
--- a/mac/tkMacXCursors.r
+++ /dev/null
@@ -1,961 +0,0 @@
-/*
- * tkMacXCursors.r --
- *
- * This file defines a set of Macintosh cursor resources that
- * emulate the X cursor set. All of these cursors were
- * constructed and donated by Grant Neufeld. (gneufeld@ccs.carleton.ca)
- *
- *
- * Copyright (c) 1995-1996 Sun Microsystems, Inc.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: tkMacXCursors.r,v 1.2 1998/09/14 18:23:40 stanton Exp $
- */
-
-/*
- * All of the X cursors are defined as 'CURS' resources. However, a
- * subset of the X cursors are also defined as 'crsr' resources. Tk
- * will attempt to first use the color cursors ('crsr') if it doesn't
- * exist it will attempt to use the black & white cursor ('CURS').
- */
-
-data 'CURS' (3000, "X_cursor") {
- $"E007 F00F F81F 7C3E 3E7C 1FF8 0FF0 07E0"
- $"07E0 0FF0 1FF8 3E7C 7C3E F81F F00F E007"
- $"0000 6006 700E 381C 1C38 0E70 07E0 03C0"
- $"03C0 07E0 0E70 1C38 381C 700E 6006 0000"
- $"0007 0007"
-};
-
-data 'CURS' (3001, "arrow") {
- $"0000 0006 001E 007C 01FC 07F8 00F8 01F0"
- $"03B0 0720 0E20 1C00 3800 7000 2000 0000"
- $"0007 001F 007F 01FE 07FE 1FFC 7FFC 03F8"
- $"07F8 0FF0 1F70 3E60 7C60 F840 7040 2000"
- $"0001 000E"
-};
-
-data 'CURS' (3002, "based_arrow_down") {
- $"0000 0000 0000 1FE0 0000 1FE0 0300 0300"
- $"0300 0B40 0780 0300 0000 0000 0000 0000"
- $"0000 0000 0000 1FE0 0000 1FE0 0780 0780"
- $"3FF0 1FE0 0FC0 0780 0300 0000 0000 0000"
- $"000B 0006"
-};
-
-data 'CURS' (3003, "based_arrow_up") {
- $"0000 0000 0000 0000 0300 0780 0B40 0300"
- $"0300 0300 1FE0 0000 1FE0 0000 0000 0000"
- $"0000 0000 0000 0300 0780 0FC0 1FE0 3FF0"
- $"0780 0780 1FE0 0000 1FE0 0000 0000 0000"
- $"0004 0006"
-};
-
-data 'CURS' (3004, "boat") {
- $"0000 0000 0000 0000 0100 03C0 8460 FFFF"
- $"0018 0020 0040 FFC0 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0100 03C0 87E0 FFFF"
- $"FFF8 FFE0 FFC0 FFC0 0000 0000 0000 0000"
- $"0007 000F"
-};
-
-data 'CURS' (3005, "bogosity") {
- $"0000 711C 1110 1110 1110 7FFC 5114 5114"
- $"5114 5114 7FFC 1110 1110 1110 711C 0000"
- $"0000 0000 0000 0000 0000 7FFC 7FFC 7FFC"
- $"7FFC 7FFC 7FFC 0000 0000 0000 0000 0000"
- $"0001 0007"
-};
-
-data 'CURS' (3006, "bottom_left_corner") {
- $"0000 0000 0000 0000 C000 C020 C840 C880"
- $"C900 CA00 CC00 CFC0 C000 C000 FFF0 FFF0"
- $"0000 0000 0000 0000 0000 0020 0840 0880"
- $"0900 0A00 0C00 0FC0 0000 0000 0000 0000"
- $"000F 0000"
-};
-
-data 'CURS' (3007, "bottom_right_corner") {
- $"0000 0000 0000 0000 0003 0403 0213 0113"
- $"0093 0053 0033 03F3 0003 0003 0FFF 0FFF"
- $"0000 0000 0000 0000 0000 0400 0210 0110"
- $"0090 0050 0030 03F0 0000 0000 0000 0000"
- $"000F 000F"
-};
-
-data 'CURS' (3008, "bottom_side") {
- $"0000 0000 0100 0100 0100 0100 0100 1110"
- $"0920 0540 0380 0100 0000 7FFC 7FFC 0000"
- $"0000 0000 0100 0100 0100 0100 0100 1110"
- $"0920 0540 0380 0100 0000 0000 0000 0000"
- $"000B 0007"
-};
-
-data 'CURS' (3009, "bottom_tee") {
- $"0000 0000 0000 0180 0180 0180 0180 0180"
- $"0180 0180 7FFE 7FFE 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"000B 0007"
-};
-
-data 'CURS' (3010, "box_spiral") {
- $"FFFE 8000 BFFE A002 AFFA A80A ABEA AA2A"
- $"AAAA ABAA A82A AFEA A00A BFFA 8002 FFFE"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0008 0008"
-};
-
-data 'CURS' (3011, "center_ptr") {
- $"0000 0300 0300 0780 0780 0FC0 0FC0 1FE0"
- $"1FE0 3330 2310 0300 0300 0300 0300 0000"
- $"0300 0780 0780 0FC0 0FC0 1FE0 1FE0 3FF0"
- $"3FF0 7FF8 77B8 6798 0780 0780 0780 0780"
- $"0001 0006"
-};
-
-data 'CURS' (3012, "circle") {
- $"0000 03C0 0FF0 1FF8 3C3C 381C 700E 700E"
- $"700E 700E 381C 3C3C 1FF8 0FF0 03C0 0000"
- $"03C0 0FF0 1FF8 3FFC 7FFE 7C3E F81F F81F"
- $"F81F F81F 7C3E 7FFE 3FFC 1FF8 0FF0 03C0"
- $"0007 0007"
-};
-
-data 'CURS' (3013, "clock") {
- $"1FF8 33CC 6466 4992 4F12 4422 63C6 3FFC"
- $"2994 2994 2994 2BD4 6996 781E 7FFE 7FFE"
- $"1FF8 3FFC 7FFE 7FFE 7FFE 7FFE 7FFE 3FFC"
- $"3FFC 3FFC 3FFC 3FFC 7FFE 7FFE 7FFE 7FFE"
- $"0004 0008"
-};
-
-data 'CURS' (3014, "coffee_mug") {
- $"03F8 0C06 1001 1C07 33F9 7001 D001 9001"
- $"960D DA55 7A55 36ED 10A1 1001 0802 07FC"
- $"03F8 0FFE 1FFF 1FFF 3FFF 7FFF FFFF FFFF"
- $"FFFF FFFF 7FFF 3FFF 1FFF 1FFF 0FFE 07FC"
- $"0004 0003"
-};
-
-data 'CURS' (3015, "cross") {
- $"0280 0280 0280 0280 0280 0280 FEFE 0000"
- $"FEFE 0280 0280 0280 0280 0280 0280 0000"
- $"0380 0380 0380 0380 0380 0380 FFFE FFFE"
- $"FFFE 0380 0380 0380 0380 0380 0380 0000"
- $"0007 0007"
-};
-
-data 'CURS' (3016, "cross_reverse") {
- $"4284 A28A 5294 2AA8 16D0 0AA0 FD7E 0280"
- $"FD7E 0AA0 16D0 2AA8 5294 A28A 4284 0000"
- $"4384 E38E 739C 3BB8 1FF0 0FE0 FFFE FFFE"
- $"FFFE 0FE0 1FF0 3BB8 739C E38E 4384 0000"
- $"0007 0007"
-};
-
-data 'CURS' (3017, "crosshair") {
- $"0100 0100 0100 0100 0100 0100 0100 FEFE"
- $"0100 0100 0100 0100 0100 0100 0100 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0007 0007"
-};
-
-data 'CURS' (3018, "diamond_cross") {
- $"0280 06C0 0AA0 1290 2288 4284 FEFE 0000"
- $"FEFE 4284 2288 1290 0AA0 06C0 0280 0000"
- $"0280 06C0 0EE0 1EF0 3EF8 7EFC FEFE 0000"
- $"FEFE 7EFC 3EF8 1EF0 0EE0 06C0 0280 0000"
- $"0007 0007"
-};
-
-data 'CURS' (3019, "dot") {
- $"0000 0000 0780 1FE0 1FE0 3FF0 3FF0 3FF0"
- $"3FF0 1FE0 1FE0 0780 0000 0000 0000 0000"
- $"0000 0780 1FE0 3FF0 3FF0 7FF8 7FF8 7FF8"
- $"7FF8 3FF0 3FF0 1FE0 0780 0000 0000 0000"
- $"0006 0006"
-};
-
-data 'CURS' (3020, "dotbox") {
- $"0000 0000 3FFC 2004 2004 2004 2004 2184"
- $"2184 2004 2004 2004 2004 3FFC 0000 0000"
- $"0000 0000 3FFC 3FFC 300C 300C 318C 33CC"
- $"33CC 318C 300C 300C 3FFC 3FFC 0000 0000"
- $"0007 0007"
-};
-
-data 'CURS' (3021, "double_arrow") {
- $"0000 0180 03C0 07E0 0DB0 1998 0180 0180"
- $"0180 0180 1998 0DB0 07E0 03C0 0180 0000"
- $"0180 03C0 07E0 0FF0 1FF8 3FFC 3BDC 03C0"
- $"03C0 3BDC 3FFC 1FF8 0FF0 07E0 03C0 0180"
- $"0007 0007"
-};
-
-data 'CURS' (3022, "draft_large") {
- $"0000 0002 000C 003C 00F8 03F8 0FF0 00F0"
- $"0160 0260 0440 0840 1000 2000 4000 0000"
- $"0003 000F 003E 00FE 03FC 0FFC 3FF8 FFF8"
- $"03F0 07F0 0EE0 1CE0 38C0 70C0 E080 4080"
- $"0001 000E"
-};
-
-data 'CURS' (3023, "draft_small") {
- $"0000 0002 000C 003C 00F8 03F8 0070 00B0"
- $"0120 0220 0400 0800 1000 2000 4000 0000"
- $"0003 000F 003E 00FE 03FC 0FFC 3FF8 01F8"
- $"03F0 0770 0E60 1C60 3840 7040 E000 4000"
- $"0001 000E"
-};
-
-data 'CURS' (3024, "draped_box") {
- $"0000 0000 3FFC 2244 2664 2C34 381C 2184"
- $"2184 381C 2C34 2664 2244 3FFC 0000 0000"
- $"0000 0000 3FFC 3E7C 3E7C 3C3C 399C 23C4"
- $"23C4 399C 3C3C 3E7C 3E7C 3FFC 0000 0000"
- $"0007 0007"
-};
-
-data 'CURS' (3025, "exchange") {
- $"0000 47C0 6FE0 7C30 4810 4C00 7E00 0000"
- $"0000 00FC 0064 1024 187C 0FEC 07C4 0000"
- $"C7C0 EFE0 FFF0 FFF8 FC38 FE10 FF00 FF80"
- $"03FE 01FE 10FE 387E 3FFE 1FFE 0FEE 07C6"
- $"0007 0007"
-};
-
-data 'CURS' (3026, "fleur") {
- $"0000 0180 03C0 07E0 0180 1188 318C 7FFE"
- $"7FFE 318C 1188 0180 07E0 03C0 0180 0000"
- $"0180 03C0 07E0 0FF0 17E8 3BDC 7FFE FFFF"
- $"FFFF 7FFE 3BDC 17E8 0FF0 07E0 03C0 0180"
- $"0007 0007"
-};
-
-data 'CURS' (3027, "gobbler") {
- $"0000 0078 0070 4036 4FB0 7FF0 7E30 7C30"
- $"3038 00F0 0FE0 0400 0400 0400 0F00 0000"
- $"00FC 00FC E0FF FFFF FFFF FFF8 FFF8 FFF8"
- $"FFFC 7FFC 3FF8 1FF0 0E00 1F80 1F80 1F80"
- $"0003 000E"
-};
-
-data 'CURS' (3028, "gumby") {
- $"3F00 10C0 C820 EAA0 C820 CBA0 F838 383E"
- $"0826 0826 092E 0926 0920 1110 2108 3EF8"
- $"3F00 1FC0 CFE0 EFE0 CFE0 CFE0 FFF8 3FFE"
- $"0FE6 0FE6 0FEE 0FE6 0FE0 1FF0 3FF8 3EF8"
- $"0000 0002"
-};
-
-data 'CURS' (3029, "hand1") {
- $"000C 003C 00F0 01E0 03C0 07E0 0FF0 2FE0"
- $"7FF0 5FF0 07E0 07C0 4A00 6200 3400 1800"
- $"000C 003C 00F0 01E0 03C0 07E0 0FF0 2FE0"
- $"7FF0 7FF0 7FE0 7FC0 7E00 7E00 3C00 1800"
- $"0000 000D"
-};
-
-data 'CURS' (3030, "hand2") {
- $"0000 3FC0 4020 3F10 0808 0708 0808 0714"
- $"0822 0641 0182 0124 0088 0050 0020 0000"
- $"0000 3FC0 7FE0 3FF0 0FF8 07F8 0FF8 07FC"
- $"0FFE 07FF 01FE 01FC 00F8 0070 0020 0000"
- $"0002 0001"
-};
-
-data 'CURS' (3031, "heart") {
- $"0000 3EF8 638C C106 8002 8002 8002 8002"
- $"C006 600C 3018 1830 0C60 06C0 0380 0000"
- $"0000 3EF8 7FFC FFFE FFFE FFFE FFFE FFFE"
- $"FFFE 7FFC 3FF8 1FF0 0FE0 07C0 0380 0000"
- $"0003 0007"
-};
-
-data 'CURS' (3032, "icon") {
- $"FFFF D555 AAAB D555 A00B D005 A00B D005"
- $"A00B D005 A00B D005 AAAB D555 AAAB FFFF"
- $"FFFF FFFF FFFF FFFF F00F F00F F00F F00F"
- $"F00F F00F F00F F00F FFFF FFFF FFFF FFFF"
- $"0007 0007"
-};
-
-data 'CURS' (3033, "iron_cross") {
- $"0000 3FFC 1FF8 4FF2 67E6 73CE 799E 7FFE"
- $"7FFE 799E 73CE 67E6 4FF2 1FF8 3FFC 0000"
- $"7FFE 7FFE FFFF FFFF FFFF FFFF FFFF FFFF"
- $"FFFF FFFF FFFF FFFF FFFF FFFF 7FFE 7FFE"
- $"0007 0006"
-};
-
-data 'CURS' (3034, "left_ptr") {
- $"0000 0800 0C00 0E00 0F00 0F80 0FC0 0FE0"
- $"0FF0 0F80 0D80 08C0 00C0 0060 0060 0000"
- $"1800 1C00 1E00 1F00 1F80 1FC0 1FE0 1FF0"
- $"1FF8 1FFC 1FC0 1DE0 19E0 10F0 00F0 0070"
- $"0001 0004"
-};
-
-data 'CURS' (3035, "left_side") {
- $"0000 6000 6000 6080 6100 6200 6400 6FFC"
- $"6400 6200 6100 6080 6000 6000 0000 0000"
- $"0000 0000 0000 0080 0100 0200 0400 0FFC"
- $"0400 0200 0100 0080 0000 0000 0000 0000"
- $"0007 0004"
-};
-
-data 'CURS' (3036, "left_tee") {
- $"0000 0C00 0C00 0C00 0C00 0C00 0C00 0FF8"
- $"0FF8 0C00 0C00 0C00 0C00 0C00 0C00 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0007 0004"
-};
-
-data 'CURS' (3037, "leftbutton") {
- $"8002 7FFC 7FFC 4444 4554 4554 4554 4554"
- $"4444 7FFC 7FFC 7FFC 7FFC 7FFC 7FFC 8002"
- $"FFFE FFFE FFFE FFFE FFFE FFFE FFFE FFFE"
- $"FFFE FFFE FFFE FFFE FFFE FFFE FFFE FFFE"
- $"0004 0003"
-};
-
-data 'CURS' (3038, "ll_angle") {
- $"0000 0000 0000 0C00 0C00 0C00 0C00 0C00"
- $"0C00 0C00 0FF8 0FF8 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"000B 0004"
-};
-
-data 'CURS' (3039, "lr_angle") {
- $"0000 0000 0000 0030 0030 0030 0030 0030"
- $"0030 0030 1FF0 1FF0 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"000B 000B"
-};
-
-data 'CURS' (3040, "man") {
- $"0380 1EF0 0280 8100 4387 244B 1D70 0540"
- $"0440 0280 0440 0920 1290 1450 783C F83F"
- $"0380 1FF0 0380 8100 4387 27CB 1FF0 07C0"
- $"07C0 0380 07C0 0FE0 1EF0 1C70 783C F83F"
- $"0001 0007"
-};
-
-data 'CURS' (3041, "middlebutton") {
- $"8002 7FFC 7FFC 4444 5454 5454 5454 5454"
- $"4444 7FFC 7FFC 7FFC 7FFC 7FFC 7FFC 8002"
- $"FFFE FFFE FFFE FFFE FFFE FFFE FFFE FFFE"
- $"FFFE FFFE FFFE FFFE FFFE FFFE FFFE FFFE"
- $"0004 0007"
-};
-
-data 'CURS' (3042, "mouse") {
- $"0600 0100 0180 0FF0 1008 17E8 1428 1428"
- $"17E8 1008 1008 1008 1008 1008 1008 0FF0"
- $"0600 0100 0180 0FF0 1FF8 1FF8 1FF8 1FF8"
- $"1FF8 1FF8 1FF8 1FF8 1FF8 1FF8 1FF8 0FF0"
- $"0000 0000"
-};
-
-data 'CURS' (3043, "pencil") {
- $"0000 00F0 0088 0108 0190 0270 0220 0440"
- $"0440 0880 0880 1100 1E00 1C00 1800 1000"
- $"0000 00F0 00F8 01F8 01F0 03F0 03E0 07C0"
- $"07C0 0F80 0F80 1F00 1E00 1C00 1800 1000"
- $"000F 0003"
-};
-
-data 'CURS' (3044, "pirate") {
- $"03C0 07E0 0FF0 1998 1998 0FF0 07E0 03C0"
- $"43C2 43C3 2184 1C38 03C0 0FF1 781F 4002"
- $"07E0 0FF0 1FF8 3FFC 3FFC 1FF8 0FF0 47E2"
- $"E7E7 E7E7 7FFF 3FFC 1FF9 7FFF FFFF F81F"
- $"000A 0007"
-};
-
-data 'CURS' (3045, "plus") {
- $"0000 0000 0000 0180 0180 0180 0180 1FF8"
- $"1FF8 0180 0180 0180 0180 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0007 0007"
-};
-
-data 'CURS' (3046, "question_arrow") {
- $"07C0 0FE0 1C70 1830 1C30 0C70 00E0 03C0"
- $"0380 0280 0280 0EE0 06C0 0380 0100 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 3FF8 1FF0 0FE0 07C0 0380 0100"
- $"000E 0007"
-};
-
-data 'CURS' (3047, "right_ptr") {
- $"0000 0010 0030 0070 00F0 01F0 03F0 07F0"
- $"0FF0 01F0 01B0 0310 0300 0600 0600 0000"
- $"0018 0038 0078 00F8 01F8 03F8 07F8 0FF8"
- $"1FF8 3FF8 03F8 07B8 0798 0F08 0F00 0E00"
- $"0001 000B"
-};
-
-data 'CURS' (3048, "right_side") {
- $"0000 0000 0006 0006 0106 0086 0046 0026"
- $"3FF6 0026 0046 0086 0106 0006 0006 0000"
- $"0000 0000 0000 0000 0100 0080 0040 0020"
- $"3FF0 0020 0040 0080 0100 0000 0000 0000"
- $"0008 000B"
-};
-
-data 'CURS' (3049, "right_tee") {
- $"0000 0030 0030 0030 0030 0030 0030 1FF0"
- $"1FF0 0030 0030 0030 0030 0030 0030 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0007 000A"
-};
-
-data 'CURS' (3050, "rightbutton") {
- $"8002 7FFC 7FFC 4444 5544 5544 5544 5544"
- $"4444 7FFC 7FFC 7FFC 7FFC 7FFC 7FFC 8002"
- $"FFFE FFFE FFFE FFFE FFFE FFFE FFFE FFFE"
- $"FFFE FFFE FFFE FFFE FFFE FFFE FFFE FFFE"
- $"0004 0003"
-};
-
-data 'CURS' (3051, "rtl_logo") {
- $"0000 7FFE 4022 4022 4022 7FE2 4422 4422"
- $"4422 4422 47FE 4402 4402 4402 7FFE 0000"
- $"0000 7FFE 7FFE 6076 7FF6 7FF6 7C36 6C36"
- $"6C36 6C3E 6FFE 6FFE 6E06 7FFE 7FFE 0000"
- $"0007 0007"
-};
-
-data 'CURS' (3052, "sailboat") {
- $"0000 0040 0040 0160 0160 0360 0370 0770"
- $"0770 0F78 0F78 1F78 1F7C 3E38 0000 0000"
- $"0040 00E0 01E0 03F0 03F0 07F0 07F8 0FF8"
- $"0FF8 1FFC 1FFC 3FFC 3FFE 7F7C 7E38 0000"
- $"000C 0008"
-};
-
-data 'CURS' (3053, "sb_down_arrow") {
- $"0280 0280 0280 0280 0280 0280 0280 0280"
- $"0280 0280 0280 0FE0 07C0 0380 0100 0000"
- $"0380 0380 0380 0380 0380 0380 0380 0380"
- $"0380 0380 0380 1FF0 0FE0 07C0 0380 0100"
- $"000E 0007"
-};
-
-data 'CURS' (3054, "sb_h_double_arrow") {
- $"0000 0000 0000 0000 0810 1818 3FFC 781E"
- $"3FFC 1818 0810 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0810 1818 381C 7FFE FFFF"
- $"7FFE 381C 1818 0810 0000 0000 0000 0000"
- $"0007 0007"
-};
-
-data 'CURS' (3055, "sb_left_arrow") {
- $"0000 0000 0000 0000 0800 1800 3FFF 7800"
- $"3FFF 1800 0800 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0800 1800 3800 7FFF FFFF"
- $"7FFF 3800 1800 0800 0000 0000 0000 0000"
- $"0007 0001"
-};
-
-data 'CURS' (3056, "sb_right_arrow") {
- $"0000 0000 0000 0000 0000 0010 0018 FFFC"
- $"001E FFFC 0018 0010 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0010 0018 001C FFFE"
- $"FFFF FFFE 001C 0018 0010 0000 0000 0000"
- $"0008 000E"
-};
-
-data 'CURS' (3057, "sb_up_arrow") {
- $"0000 0080 01C0 03E0 07F0 0140 0140 0140"
- $"0140 0140 0140 0140 0140 0140 0140 0140"
- $"0080 01C0 03E0 07F0 0FF8 01C0 01C0 01C0"
- $"01C0 01C0 01C0 01C0 01C0 01C0 01C0 01C0"
- $"0001 0008"
-};
-
-data 'CURS' (3058, "sb_v_double_arrow") {
- $"0000 0100 0380 07C0 0FE0 0280 0280 0280"
- $"0280 0280 0280 0FE0 07C0 0380 0100 0000"
- $"0100 0380 07C0 0FE0 1FF0 0380 0380 0380"
- $"0380 0380 0380 1FF0 0FE0 07C0 0380 0100"
- $"0007 0007"
-};
-
-data 'CURS' (3059, "shuttle") {
- $"0020 0070 00F8 01DE 05DE 09DE 11DE 11DE"
- $"11DE 11DE 31DE 71DE FDDE 1888 0078 0030"
- $"0020 0070 00F8 01FE 07FE 0FFE 1FFE 1FFE"
- $"1FFE 1FFE 3FFE 7FFE FFFE 18F8 0078 0030"
- $"0000 000A"
-};
-
-data 'CURS' (3060, "sizing") {
- $"0000 7F80 4000 4000 4000 47E0 4420 4422"
- $"4422 0422 07E2 0012 000A 0006 01FE 0000"
- $"FFC0 FFC0 FFC0 E000 EFF0 EFF0 EC37 EC37"
- $"EC37 EC37 0FF7 0FFF 001F 03FF 03FF 03FF"
- $"000E 000E"
-};
-
-data 'CURS' (3061, "spider") {
- $"2010 1020 1020 0840 0840 8787 6798 1FE0"
- $"1FE0 6798 8787 0840 0840 1020 1020 2010"
- $"7038 3870 3870 1CE0 9FE7 EFDF FFFF 7FF8"
- $"7FF8 FFFF EFDF 9FE7 1CE0 3870 3870 7038"
- $"0007 0007"
-};
-
-data 'CURS' (3062, "spraycan") {
- $"0018 0040 0D18 1E40 1A18 3F00 2100 3900"
- $"2900 3900 2900 3900 3900 2100 2100 3F00"
- $"0000 0000 0C00 1E00 1E00 3F00 3F00 3F00"
- $"3F00 3F00 3F00 3F00 3F00 3F00 3F00 3F00"
- $"0002 0007"
-};
-
-data 'CURS' (3063, "star") {
- $"0100 0280 0280 0280 0440 0440 0440 3938"
- $"C006 3838 0920 1290 2448 2828 3018 2008"
- $"0100 0380 0380 0380 07C0 07C0 07C0 3FF8"
- $"FFFE 3FF8 0FE0 1EF0 3C78 3838 3018 2008"
- $"0007 0007"
-};
-
-data 'CURS' (3064, "target") {
- $"0000 0380 0FE0 1C70 3018 600C C106 C286"
- $"C106 600C 3018 1C70 0FE0 0380 0000 0000"
- $"0000 0380 0FE0 1FF0 3C78 701C E38E E38E"
- $"E38E 701C 3C78 1FF0 0FE0 0380 0000 0000"
- $"0007 0007"
-};
-
-data 'CURS' (3065, "tcross") {
- $"0100 0100 0100 0100 0100 0100 0100 FFFE"
- $"0100 0100 0100 0100 0100 0100 0100 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0007 0007"
-};
-
-data 'CURS' (3066, "top_left_arrow") {
- $"0000 6000 7800 3E00 3F80 1FE0 1E00 0D00"
- $"0C80 0440 0420 0010 0008 0004 0000 0000"
- $"E000 F800 FE00 7F80 7FE0 3FF8 3FFE 1F80"
- $"1FC0 0EE0 0E70 0638 061C 020E 0204 0000"
- $"0001 0001"
-};
-
-data 'CURS' (3067, "top_left_corner") {
- $"FFF0 FFF0 C000 C000 CFC0 CC00 CA00 C900"
- $"C880 C840 C020 C000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0FC0 0C00 0A00 0900"
- $"0880 0840 0020 0000 0000 0000 0000 0000"
- $"0000 0000"
-};
-
-data 'CURS' (3068, "top_right_corner") {
- $"0FFF 0FFF 0003 0003 03F3 0033 0053 0093"
- $"0113 0213 0403 0003 0000 0000 0000 0000"
- $"0000 0000 0000 0000 03F0 0030 0050 0090"
- $"0110 0210 0400 0000 0000 0000 0000 0000"
- $"0000 000F"
-};
-
-data 'CURS' (3069, "top_side") {
- $"0000 7FFC 7FFC 0000 0100 0380 0540 0920"
- $"1110 0100 0100 0100 0100 0100 0000 0000"
- $"0000 0000 0000 0000 0100 0380 0540 0920"
- $"1110 0100 0100 0100 0100 0100 0000 0000"
- $"0004 0007"
-};
-
-data 'CURS' (3070, "top_tee") {
- $"0000 0000 0000 0000 7FFE 7FFE 0180 0180"
- $"0180 0180 0180 0180 0180 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0004 0007"
-};
-
-data 'CURS' (3071, "trek") {
- $"0100 0000 0380 07C0 0FE0 0EE0 0FE0 07C0"
- $"0380 0100 0BA0 0D60 0920 0820 0820 0000"
- $"0000 0380 07C0 0FE0 1FF0 1FF0 1FF0 0FE0"
- $"07C0 0BA0 1FF0 1FF0 1FF0 1D70 1C70 0820"
- $"0000 0007"
-};
-
-data 'CURS' (3072, "ul_angle") {
- $"0000 0000 0000 0FF8 0FF8 0C00 0C00 0C00"
- $"0C00 0C00 0C00 0C00 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0003 0004"
-};
-
-data 'CURS' (3073, "umbrella") {
- $"0000 0890 0228 49A6 27C8 1930 610C 0100"
- $"0100 0100 0100 0100 0140 0140 0080 0000"
- $"0000 0FF0 1FF8 7FFE 7FFC FFFE FBBE E38E"
- $"0380 0380 0380 03C0 03E0 03E0 01C0 0080"
- $"0004 0007"
-};
-
-data 'CURS' (3074, "ur_angle") {
- $"0000 0000 0000 0000 1FF0 1FF0 0030 0030"
- $"0030 0030 0030 0030 0030 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0004 000B"
-};
-
-data 'CURS' (3075, "watch") {
- $"07E0 07E0 07E0 07E0 0810 1088 1088 108C"
- $"138C 1008 1008 0810 07E0 07E0 07E0 07E0"
- $"07E0 07E0 07E0 07E0 0FF0 1FF8 1FF8 1FFC"
- $"1FFC 1FF8 1FF8 0FF0 07E0 07E0 07E0 07E0"
- $"0008 000D"
-};
-
-data 'CURS' (3076, "xterm") {
- $"0C60 0280 0100 0100 0100 0100 0100 0100"
- $"0100 0100 0100 0100 0100 0100 0280 0C60"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"000B 0007"
-};
-
-/*
- * The following are color versions of some of the
- * cursors defined above. The color cursors will be
- * used if the exist in preference to the black & white
- * cursors.
- */
-
-data 'crsr' (3004, "boat", purgeable) {
- $"8001 0000 0060 0000 0092 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0100 03C0"
- $"8460 FFFF 0018 0020 0040 FFC0 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0100 03C0"
- $"87E0 FFFF FFF8 FFE0 FFC0 FFC0 0000 0000"
- $"0000 0000 0007 000F 0000 0000 0000 0000"
- $"0000 0000 8008 0000 0000 0010 0010 0000"
- $"0000 0000 0000 0048 0000 0048 0000 0000"
- $"0004 0001 0004 0000 0000 0000 0112 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 000F 0000 0000 0000 00FF FF00"
- $"0000 F000 0F32 25F0 0000 6FFF FFFF FFFF"
- $"FFFF 2222 2222 221F F000 2222 2222 21F0"
- $"0000 3333 3333 4F00 0000 FFFF FFFF FF00"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0007 0000 FFFF FFFF"
- $"FFFF 0001 BBBB BBBB BBBB 0002 EEEE EEEE"
- $"EEEE 0003 DDDD DDDD DDDD 0004 CCCC CCCC"
- $"CCCC 0005 4444 4444 4444 0006 1111 1111"
- $"1111 000F 0000 0000 0000"
-};
-
-data 'crsr' (3013, "clock") {
- $"8001 0000 0060 0000 0092 0000 0000 0000"
- $"0000 0000 1FF8 33CC 6466 4992 4F12 4422"
- $"63C6 3FFC 2994 2994 2994 2BD4 6996 781E"
- $"7FFE 7FFE 1FF8 3FFC 7FFE 7FFE 7FFE 7FFE"
- $"7FFE 3FFC 3FFC 3FFC 3FFC 3FFC 7FFE 7FFE"
- $"7FFE 7FFE 0004 0008 0000 0000 0000 0000"
- $"0000 0000 8008 0000 0000 0010 0010 0000"
- $"0000 0000 0000 0048 0000 0048 0000 0000"
- $"0004 0001 0004 0000 0000 0000 0112 0000"
- $"0000 000F FFFF FFFF F000 00F6 05FF FF50"
- $"6F00 0F60 5F00 56F5 06F0 0F00 F021 F30F"
- $"00F0 0F00 F6F1 000F 00F0 0F00 5F00 00F5"
- $"00F0 0F60 05FF FF50 06F0 00FF FFFF FFFF"
- $"FF00 00F0 F001 100F 0F00 00F0 F001 100F"
- $"0F00 00F0 F021 120F 0F00 00F0 F01F F10F"
- $"0F00 0FF0 F021 120F 0FF0 0FF4 F500 005F"
- $"4FF0 0FFF FFFF FFFF FFF0 0FFF FFFF FFFF"
- $"FFF0 0000 0000 0000 0007 0000 FFFF FFFF"
- $"FFFF 0001 4444 4444 4444 0002 AAAA AAAA"
- $"AAAA 0003 EEEE EEEE EEEE 0004 5555 5555"
- $"5555 0005 DDDD DDDD DDDD 0006 7777 7777"
- $"7777 000F 0000 0000 0000"
-};
-
-data 'crsr' (3014, "coffee_mug") {
- $"8001 0000 0060 0000 0092 0000 0000 0000"
- $"0000 0000 03F8 0C06 1001 1C07 33F9 7001"
- $"D001 9001 960D DA55 7A55 36ED 10A1 1001"
- $"0802 07FC 03F8 0FFE 1FFF 1FFF 3FFF 7FFF"
- $"FFFF FFFF FFFF FFFF 7FFF 3FFF 1FFF 1FFF"
- $"0FFE 07FC 0004 0003 0000 0000 0000 0000"
- $"0000 0000 8008 0000 0000 0010 0010 0000"
- $"0000 0000 0000 0048 0000 0048 0000 0000"
- $"0004 0001 0004 0000 0000 0000 0112 0000"
- $"0000 0000 00FF FFFF F000 0000 FF42 2222"
- $"4FF0 000F 4221 1111 224F 000F FF11 1111"
- $"1FFF 00FF 24FF FFFF F42F 0F5F 2222 2222"
- $"222F F52F 2222 2222 222F F40F 2222 2222"
- $"222F F40F 4FF2 2224 FF2F F52F F2F2 2F2F"
- $"2F2F 0F5F F2F2 535F 2F2F 00FF 4FF2 F3F4"
- $"FF2F 000F 2222 F2F2 222F 000F 4222 2222"
- $"224F 0000 F422 2222 24F0 0000 0FFF FFFF"
- $"FF00 0000 0000 0000 0006 0000 FFFF FFFF"
- $"FFFF 0001 CCCC 9999 6666 0002 CCCC CCCC"
- $"FFFF 0003 3333 3333 6666 0004 9999 9999"
- $"FFFF 0005 6666 6666 CCCC 000F 0000 0000"
- $"0000"
-};
-
-data 'crsr' (3027, "gobbler") {
- $"8001 0000 0060 0000 0092 0000 0000 0000"
- $"0000 0000 0000 0078 0070 4036 4FB0 7FF0"
- $"7E30 7C30 3038 00F0 0FE0 0400 0400 0400"
- $"0F00 0000 00FC 00FC E0FF FFFF FFFF FFF8"
- $"FFF8 FFF8 FFFC 7FFC 3FF8 1FF0 0E00 1F80"
- $"1F80 1F80 0003 000E 0000 0000 0000 0000"
- $"0000 0000 8008 0000 0000 0010 0010 0000"
- $"0000 0000 0000 0048 0000 0048 0000 0000"
- $"0004 0001 0004 0000 0000 0000 0112 0000"
- $"0000 0000 0000 0000 0000 0000 0000 0222"
- $"2000 0000 0000 0111 0000 0300 0000 0011"
- $"0220 0100 1616 1011 0000 0361 6111 1111"
- $"0000 0111 1114 4415 0000 0311 1144 4451"
- $"0000 0011 4444 4415 1000 0004 4444 5151"
- $"0000 0000 1515 1510 0000 0000 0200 0000"
- $"0000 0000 0300 0000 0000 0000 0200 0000"
- $"0000 0000 2323 0000 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0006 0000 FFFF FFFF"
- $"FFFF 0001 CCCC 9999 6666 0002 DDDD 0000"
- $"0000 0003 FFFF 6666 3333 0004 CCCC CCCC"
- $"CCCC 0005 8888 8888 8888 0006 FFFF CCCC"
- $"9999"
-};
-
-data 'crsr' (3028, "gumby") {
- $"8001 0000 0060 0000 0092 0000 0000 0000"
- $"0000 0000 3F00 10C0 C820 EAA0 C820 CBA0"
- $"F838 383E 0826 0826 092E 0926 0920 1110"
- $"2108 3EF8 3F00 1FC0 CFE0 EFE0 CFE0 CFE0"
- $"FFF8 3FFE 0FE6 0FE6 0FEE 0FE6 0FE0 1FF0"
- $"3FF8 3EF8 0000 0002 0000 0000 0000 0000"
- $"0000 0000 8008 0000 0000 0010 0010 0000"
- $"0000 0000 0000 0048 0000 0048 0000 0000"
- $"0004 0001 0004 0000 0000 0000 0112 0000"
- $"0000 00FF FFFF 0000 0000 000F 1212 FF00"
- $"0000 FF00 F131 31F0 0000 FFF0 F3F3 F3F0"
- $"0000 FF00 F131 31F0 0000 FF00 F2FF F2F0"
- $"0000 4FFF F121 21FF F000 00FF F212 12FF"
- $"FF40 0000 F121 21F0 0FF0 0000 F212 12F0"
- $"0FF0 0000 F12F 21F0 FFF0 0000 F21F 12F0"
- $"0FF0 0000 F12F 21F0 0000 000F 121F 121F"
- $"0000 00F1 212F 2121 F000 00FF FFF0 FFFF"
- $"F000 0000 0000 0000 0005 0000 FFFF FFFF"
- $"FFFF 0001 0000 BBBB 0000 0002 CCCC CCCC"
- $"CCCC 0003 AAAA AAAA AAAA 0004 4444 4444"
- $"4444 000F 0000 0000 0000"
-};
-
-data 'crsr' (3031, "heart") {
- $"8001 0000 0060 0000 0092 0000 0000 0000"
- $"0000 0000 0000 3EF8 638C C106 8002 8002"
- $"8002 8002 C006 600C 3018 1830 0C60 06C0"
- $"0380 0000 0000 3EF8 7FFC FFFE FFFE FFFE"
- $"FFFE FFFE FFFE 7FFC 3FF8 1FF0 0FE0 07C0"
- $"0380 0000 0003 0007 0000 0000 0000 0000"
- $"0000 0000 8004 0000 0000 0010 0010 0000"
- $"0000 0000 0000 0048 0000 0048 0000 0000"
- $"0002 0001 0002 0000 0000 0000 00D2 0000"
- $"0000 0000 0000 0FFC FFC0 3AAB AA70 E99B"
- $"999C E665 A65C E999 999C E666 665C E999"
- $"999C D666 665C 3599 9970 0D66 65C0 0359"
- $"9700 00D6 5C00 0035 7000 000F C000 0000"
- $"0000 0000 0000 0000 0003 0000 FFFF FFFF"
- $"FFFF 0001 DDDD 0000 0000 0002 FFFF 6666"
- $"CCCC 0003 0000 0000 0000"
-};
-
-data 'crsr' (3042, "mouse", purgeable) {
- $"8001 0000 0060 0000 0092 0000 0000 0000"
- $"0000 0000 BE00 0100 0180 0FF0 1008 17E8"
- $"1428 1428 17E8 1008 1008 1008 1008 1008"
- $"1008 0FF0 FE00 0100 0180 0FF0 1FF8 1FF8"
- $"1FF8 1FF8 1FF8 1FF8 1FF8 1FF8 1FF8 1FF8"
- $"1FF8 0FF0 0001 0007 0000 0000 0000 0000"
- $"0000 0000 8008 0000 0000 0010 0010 0000"
- $"0000 0000 0000 0048 0000 0048 0000 0000"
- $"0004 0001 0004 0000 0000 0000 0112 0000"
- $"0000 1379 4AF0 0000 0000 0000 000F 0000"
- $"0000 0000 000F F000 0000 0000 FFFF FFFF"
- $"0000 000F 2111 1112 F000 000F 3655 5563"
- $"F000 000F 3513 1351 F000 000F 3533 3351"
- $"F000 000F 3655 5561 F000 000F 3311 1111"
- $"F000 000F 3333 3333 F000 000F 3333 3333"
- $"F000 000F 2222 2222 F000 000F 8888 8888"
- $"F000 000F 7888 8887 F000 0000 FFFF FFFF"
- $"0000 0000 0000 0000 000B 0000 FFFF FFFF"
- $"FFFF 0001 EEEE EEEE EEEE 0002 CCCC CCCC"
- $"CCCC 0003 DDDD DDDD DDDD 0004 4444 4444"
- $"4444 0005 2222 2222 2222 0006 5555 5555"
- $"5555 0007 AAAA AAAA AAAA 0008 BBBB BBBB"
- $"BBBB 0009 7777 7777 7777 000A 1111 1111"
- $"1111 000F 0000 0000 0000"
-};
-
-data 'crsr' (3043, "pencil", purgeable) {
- $"8001 0000 0060 0000 0092 0000 0000 0000"
- $"0000 0000 0000 00F0 0088 0108 0190 0270"
- $"0220 0440 0440 0880 0880 1100 1E00 1C00"
- $"1800 1000 0000 00F0 00F8 01F8 01F0 03F0"
- $"03E0 07C0 07C0 0F80 0F80 1F00 1E00 1C00"
- $"1800 1000 000F 0003 0000 0000 0000 0000"
- $"0000 0000 8008 0000 0000 0010 0010 0000"
- $"0000 0000 0000 0048 0000 0048 0000 0000"
- $"0004 0001 0004 0000 0000 0000 0112 0000"
- $"0000 0000 0000 0000 0000 0000 0000 FFFF"
- $"0000 0000 0000 F404 F000 0000 000F 4042"
- $"F000 0000 000F F42F 0000 0000 00F5 3FFF"
- $"0000 0000 00F3 52F0 0000 0000 0F35 1F00"
- $"0000 0000 0F53 2F00 0000 0000 F532 F000"
- $"0000 0000 F312 F000 0000 000F 352F 0000"
- $"0000 000F FFF0 0000 0000 000F FF00 0000"
- $"0000 000F F000 0000 0000 000F 0000 0000"
- $"0000 0000 0000 0000 0006 0000 FFFF FFFF"
- $"FFFF 0001 CCCC CCCC CCCC 0002 8888 8888"
- $"8888 0003 FFFF FFFF 0000 0004 DDDD 0000"
- $"0000 0005 FFFF 6666 3333 000F 0000 0000"
- $"0000"
-};
-
-data 'crsr' (3059, "shuttle") {
- $"8001 0000 0060 0000 0092 0000 0000 0000"
- $"0000 0000 0020 0070 00F8 01DE 05DE 09DE"
- $"11DE 11DE 11DE 11DE 31DE 71DE FDDE 1888"
- $"0078 0030 0020 0070 00F8 01FE 07FE 0FFE"
- $"1FFE 1FFE 1FFE 1FFE 3FFE 7FFE FFFE 18F8"
- $"0078 0030 0000 000A 0000 0000 0000 0000"
- $"0000 0000 8008 0000 0000 0010 0010 0000"
- $"0000 0000 0000 0048 0000 0048 0000 0000"
- $"0004 0001 0004 0000 0000 0000 0112 0000"
- $"0000 0000 0000 00F0 0000 0000 0000 0F3F"
- $"0000 0000 0000 F343 F000 0000 000F 3404"
- $"3FF0 0000 0F4F 3404 3FF0 0000 F55F 3404"
- $"3FF0 000F 505F 3404 3FF0 000F 005F 3404"
- $"3FF0 000F 005F 3404 3FF0 000F 005F 3404"
- $"3FF0 00F3 005F 3404 3FF0 0F33 505F 3404"
- $"3FF0 FFF3 3F4F 3404 3FF0 000F F000 1222"
- $"1000 0000 0000 0111 1000 0000 0000 0011"
- $"0000 0000 0000 0000 0006 0000 FFFF FFFF"
- $"FFFF 0001 FFFF 6666 3333 0002 DDDD 0000"
- $"0000 0003 4444 4444 4444 0004 8888 8888"
- $"8888 0005 DDDD DDDD DDDD 000F 0000 0000"
- $"0000"
-};
-
-data 'crsr' (3062, "spraycan") {
- $"8001 0000 0060 0000 0092 0000 0000 0000"
- $"0000 0000 0018 0040 0D18 1E40 1A18 3F00"
- $"2100 3900 2900 3900 2900 3900 3900 2100"
- $"2100 3F00 0000 0000 0C00 1E00 1E00 3F00"
- $"3F00 3F00 3F00 3F00 3F00 3F00 3F00 3F00"
- $"3F00 3F00 0002 0007 0000 0000 0000 0000"
- $"0000 0000 8008 0000 0000 0010 0010 0000"
- $"0000 0000 0000 0048 0000 0048 0000 0000"
- $"0004 0001 0004 0000 0000 0000 0112 0000"
- $"0000 0000 0000 0005 2000 0000 0000 0460"
- $"0000 0000 FF1F 6005 2000 000F 33F0 0460"
- $"0000 000F 10F0 0005 2000 00FF FFFF 0000"
- $"0000 00F8 170F 0000 0000 00F5 F70F 0000"
- $"0000 00FA F70F 0000 0000 00F9 F70F 0000"
- $"0000 00FA F70F 0000 0000 00F9 F70F 0000"
- $"0000 00F5 F70F 0000 0000 00F8 170F 0000"
- $"0000 00F8 170F 0000 0000 00FF FFFF 0000"
- $"0000 0000 0000 0000 000B 0000 FFFF FFFF"
- $"FFFF 0001 AAAA AAAA AAAA 0002 7777 7777"
- $"7777 0003 5555 5555 5555 0004 2222 2222"
- $"2222 0005 4444 4444 4444 0006 BBBB BBBB"
- $"BBBB 0007 DDDD DDDD DDDD 0008 EEEE EEEE"
- $"EEEE 0009 6666 6666 CCCC 000A CCCC CCCC"
- $"FFFF 000F 0000 0000 0000"
-};
-
-data 'crsr' (3063, "star") {
- $"8001 0000 0060 0000 0092 0000 0000 0000"
- $"0000 0000 0100 0280 0280 0280 0440 0440"
- $"0440 3938 C006 3838 0920 1290 2448 2828"
- $"3018 2008 0100 0380 0380 0380 07C0 07C0"
- $"07C0 3FF8 FFFE 3FF8 0FE0 1EF0 3C78 3838"
- $"3018 2008 0007 0007 0000 0000 0000 0000"
- $"0000 0000 8004 0000 0000 0010 0010 0000"
- $"0000 0000 0000 0048 0000 0048 0000 0000"
- $"0002 0001 0002 0000 0000 0000 00D2 0000"
- $"0000 0003 0000 000D C000 000D C000 000D"
- $"C000 0035 7000 0035 7000 0035 7000 0FD7"
- $"5FC0 F555 557C 0FD5 5FC0 00D7 5C00 035C"
- $"D700 0D70 35C0 0DC0 0DC0 0F00 03C0 0C00"
- $"00C0 0000 0000 0000 0002 0000 FFFF FFFF"
- $"FFFF 0001 FFFF FFFF 0000 0003 0000 0000"
- $"0000"
-};
-
-data 'crsr' (3071, "trek") {
- $"8001 0000 0060 0000 0092 0000 0000 0000"
- $"0000 0000 0100 0000 0380 07C0 0FE0 0EE0"
- $"0FE0 07C0 0380 0100 0BA0 0D60 0920 0820"
- $"0820 0000 0000 0380 07C0 0FE0 1FF0 1FF0"
- $"1FF0 0FE0 07C0 0BA0 1FF0 1FF0 1FF0 1D70"
- $"1C70 0820 0000 0007 0000 0000 0000 0000"
- $"0000 0000 8008 0000 0000 0010 0010 0000"
- $"0000 0000 0000 0048 0000 0048 0000 0000"
- $"0004 0001 0004 0000 0000 0000 0112 0000"
- $"0000 0000 0005 0000 0000 0000 0005 0000"
- $"0000 0000 00FF F000 0000 0000 0F31 3F00"
- $"0000 0000 F322 23F0 0000 0000 F110 11F0"
- $"0000 0000 F311 13F0 0000 0000 0F31 3F00"
- $"0000 0000 00FF F000 0000 0000 000F 0000"
- $"0000 0000 F0FF F0F0 0000 0000 FF0F 0FF0"
- $"0000 0000 400F 0040 0000 0000 4000 0040"
- $"0000 0000 4000 0040 0000 0000 0000 0000"
- $"0000 0000 0000 0000 0006 0000 FFFF FFFF"
- $"FFFF 0001 EEEE EEEE EEEE 0002 9999 9999"
- $"FFFF 0003 DDDD DDDD DDDD 0004 3333 3333"
- $"6666 0005 DDDD 0000 0000 000F 0000 0000"
- $"0000"
-};
-
-data 'crsr' (3075, "watch", purgeable) {
- $"8001 0000 0060 0000 0092 0000 0000 0000"
- $"0000 0000 07E0 07E0 07E0 07E0 0810 1088"
- $"1088 108C 138C 1008 1008 0810 07E0 07E0"
- $"07E0 07E0 07E0 07E0 07E0 07E0 0FF0 1FF8"
- $"1FF8 1FF8 1FF8 1FF8 1FF8 0FF0 07E0 07E0"
- $"07E0 07E0 0008 000D 0000 0000 0000 0000"
- $"0000 0000 8008 0000 0000 0010 0010 0000"
- $"0000 0000 0000 0048 0000 0048 0000 0000"
- $"0004 0001 0004 0000 0000 0000 0112 0000"
- $"0000 0000 0FFF FFF0 0000 0000 0FFF FFF0"
- $"0000 0000 0FFF FFF0 0000 0000 0FFF FFF0"
- $"0000 0000 F020 202F 0000 000F 0222 F221"
- $"F000 000F 2222 F123 F000 000F 0222 F121"
- $"FF00 000F 22FF F123 FF00 000F 0222 2221"
- $"F000 000F 2222 2213 F000 0000 F131 313F"
- $"0000 0000 0FFF FFF0 0000 0000 0FFF FFF0"
- $"0000 0000 0FFF FFF0 0000 0000 0FFF FFF0"
- $"0000 0000 0000 0000 0004 0000 FFFF FFFF"
- $"FFFF 0001 CCCC CCCC CCCC 0002 EEEE EEEE"
- $"EEEE 0003 BBBB BBBB BBBB 000F 0000 0000"
- $"0000"
-};
-
0' href='#n1660'>1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170
/* 
 * tkWindow.c --
 *
 *	This file provides basic window-manipulation procedures,
 *	which are equivalent to procedures in Xlib (and even
 *	invoke them) but also maintain the local Tk_Window
 *	structure.
 *
 * Copyright (c) 1989-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tkWindow.c,v 1.63 2004/03/17 18:15:44 das Exp $
 */

#include "tkPort.h"
#include "tkInt.h"

#if !( defined(__WIN32__) || defined(MAC_OSX_TK))
#include "tkUnixInt.h"
#endif

/* 
 * Type used to keep track of Window objects that were
 * only partically deallocated by Tk_DestroyWindow.
 */

#define HD_CLEANUP		1
#define HD_FOCUS		2
#define HD_MAIN_WIN		4
#define HD_DESTROY_COUNT	8
#define HD_DESTROY_EVENT	0x10

typedef struct TkHalfdeadWindow {
    int flags;
    struct TkWindow *winPtr;
    struct TkHalfdeadWindow *nextPtr;
} TkHalfdeadWindow;


typedef struct ThreadSpecificData {
    int numMainWindows;    /* Count of numver of main windows currently
			    * open in this thread. */
    TkMainInfo *mainWindowList;
                           /* First in list of all main windows managed
			    * by this thread. */
    TkHalfdeadWindow *halfdeadWindowList;
                           /* First in list of partially deallocated
			    * windows. */
    TkDisplay *displayList;
                           /* List of all displays currently in use by 
			    * the current thread. */
    int initialized;       /* 0 means the structures above need 
			    * initializing. */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;

/* 
 * The Mutex below is used to lock access to the Tk_Uid structs above. 
 */

TCL_DECLARE_MUTEX(windowMutex)

/*
 * Default values for "changes" and "atts" fields of TkWindows.  Note
 * that Tk always requests all events for all windows, except StructureNotify
 * events on internal windows:  these events are generated internally.
 */

static XWindowChanges defChanges = {
    0, 0, 1, 1, 0, 0, Above
};
#define ALL_EVENTS_MASK \
    KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask| \
    EnterWindowMask|LeaveWindowMask|PointerMotionMask|ExposureMask| \
    VisibilityChangeMask|PropertyChangeMask|ColormapChangeMask
static XSetWindowAttributes defAtts= {
    None,			/* background_pixmap */
    0,				/* background_pixel */
    CopyFromParent,		/* border_pixmap */
    0,				/* border_pixel */
    NorthWestGravity,		/* bit_gravity */
    NorthWestGravity,		/* win_gravity */
    NotUseful,			/* backing_store */
    (unsigned) ~0,		/* backing_planes */
    0,				/* backing_pixel */
    False,			/* save_under */
    ALL_EVENTS_MASK,		/* event_mask */
    0,				/* do_not_propagate_mask */
    False,			/* override_redirect */
    CopyFromParent,		/* colormap */
    None			/* cursor */
};

/*
 * The following structure defines all of the commands supported by
 * Tk, and the C procedures that execute them.
 */

typedef struct {
    char *name;			/* Name of command. */
    Tcl_CmdProc *cmdProc;	/* Command's string-based procedure. */
    Tcl_ObjCmdProc *objProc;	/* Command's object-based procedure. */
    int isSafe;			/* If !0, this command will be exposed in
                                 * a safe interpreter. Otherwise it will be
                                 * hidden in a safe interpreter. */
    int passMainWindow;		/* 0 means provide NULL clientData to
				 * command procedure; 1 means pass main
				 * window as clientData to command
				 * procedure. */
} TkCmd;

static TkCmd commands[] = {
    /*
     * Commands that are part of the intrinsics:
     */

    {"bell",		NULL,			Tk_BellObjCmd,		0, 1},
    {"bind",		NULL,			Tk_BindObjCmd,		1, 1},
    {"bindtags",	NULL,			Tk_BindtagsObjCmd,	1, 1},
    {"clipboard",	NULL,			Tk_ClipboardObjCmd,	0, 1},
    {"destroy",		NULL,			Tk_DestroyObjCmd,	1, 1},
    {"event",		NULL,			Tk_EventObjCmd,		1, 1},
    {"focus",		NULL,			Tk_FocusObjCmd,		1, 1},
    {"font",		NULL,			Tk_FontObjCmd,		1, 1},
    {"grab",		NULL,			Tk_GrabObjCmd,		0, 1},
    {"grid",		NULL,			Tk_GridObjCmd,		1, 1},
    {"image",		NULL,			Tk_ImageObjCmd,		1, 1},
    {"lower",		NULL,			Tk_LowerObjCmd,		1, 1},
    {"option",		NULL,			Tk_OptionObjCmd,	1, 1},
    {"pack",		NULL,			Tk_PackObjCmd,		1, 1},
    {"place",		NULL,			Tk_PlaceObjCmd,		1, 0},
    {"raise",		NULL,			Tk_RaiseObjCmd,		1, 1},
    {"selection",	NULL,			Tk_SelectionObjCmd,	0, 1},
    {"tk",		NULL,			Tk_TkObjCmd,		1, 1},
    {"tkwait",		NULL,			Tk_TkwaitObjCmd,	1, 1},
#if defined(__WIN32__) || defined(MAC_OSX_TK)
    {"tk_chooseColor",  NULL,			Tk_ChooseColorObjCmd,	0, 1},
    {"tk_chooseDirectory", NULL,		Tk_ChooseDirectoryObjCmd, 0, 1},
    {"tk_getOpenFile",  NULL,			Tk_GetOpenFileObjCmd,	0, 1},
    {"tk_getSaveFile",  NULL,			Tk_GetSaveFileObjCmd,	0, 1},
#endif
#if defined(__WIN32__) || defined(MAC_OSX_TK)
    {"tk_messageBox",   NULL,			Tk_MessageBoxObjCmd,	0, 1},
#endif
    {"update",		NULL,			Tk_UpdateObjCmd,	1, 1},
    {"winfo",		NULL,			Tk_WinfoObjCmd,		1, 1},
    {"wm",		NULL,			Tk_WmObjCmd,		0, 1},

    /*
     * Widget class commands.
     */

    {"button",		NULL,			Tk_ButtonObjCmd,	1, 0},
    {"canvas",		NULL,			Tk_CanvasObjCmd,	1, 1},
    {"checkbutton",	NULL,			Tk_CheckbuttonObjCmd,	1, 0},
    {"entry",		NULL,                   Tk_EntryObjCmd,		1, 0},
    {"frame",		NULL,			Tk_FrameObjCmd,		1, 0},
    {"label",		NULL,			Tk_LabelObjCmd,		1, 0},
    {"labelframe",	NULL,			Tk_LabelframeObjCmd,	1, 0},
    {"listbox",		NULL,			Tk_ListboxObjCmd,	1, 0},
    {"menubutton",	NULL,                   Tk_MenubuttonObjCmd,	1, 0},
    {"message",		NULL,			Tk_MessageObjCmd,	1, 0},
    {"panedwindow",	NULL,			Tk_PanedWindowObjCmd,	1, 0},
    {"radiobutton",	NULL,			Tk_RadiobuttonObjCmd,	1, 0},
    {"scale",		NULL,	                Tk_ScaleObjCmd,		1, 0},
    {"scrollbar",	Tk_ScrollbarCmd,	NULL,			1, 1},
    {"spinbox",		NULL,                   Tk_SpinboxObjCmd,	1, 0},
    {"text",		NULL,		        Tk_TextObjCmd,		1, 1},
    {"toplevel",	NULL,			Tk_ToplevelObjCmd,	0, 0},

    /*
     * Misc.
     */

#if defined(MAC_OSX_TK)
    {"::tk::unsupported::MacWindowStyle",
	    		TkUnsupported1Cmd,	NULL,			1, 1},
#endif
    {(char *) NULL,	(int (*) _ANSI_ARGS_((ClientData, Tcl_Interp *, int, CONST char **))) NULL, NULL, 0}
};

/*
 * The variables and table below are used to parse arguments from
 * the "argv" variable in Tk_Init.
 */

static int synchronize = 0;
static char *name = NULL;
static char *display = NULL;
static char *geometry = NULL;
static char *colormap = NULL;
static char *use = NULL;
static char *visual = NULL;
static int rest = 0;

static Tk_ArgvInfo argTable[] = {
    {"-colormap", TK_ARGV_STRING, (char *) NULL, (char *) &colormap,
	"Colormap for main window"},
    {"-display", TK_ARGV_STRING, (char *) NULL, (char *) &display,
	"Display to use"},
    {"-geometry", TK_ARGV_STRING, (char *) NULL, (char *) &geometry,
	"Initial geometry for window"},
    {"-name", TK_ARGV_STRING, (char *) NULL, (char *) &name,
	"Name to use for application"},
    {"-sync", TK_ARGV_CONSTANT, (char *) 1, (char *) &synchronize,
	"Use synchronous mode for display server"},
    {"-visual", TK_ARGV_STRING, (char *) NULL, (char *) &visual,
	"Visual for main window"},
    {"-use", TK_ARGV_STRING, (char *) NULL, (char *) &use,
	"Id of window in which to embed application"},
    {"--", TK_ARGV_REST, (char *) 1, (char *) &rest,
	"Pass all remaining arguments through to script"},
    {(char *) NULL, TK_ARGV_END, (char *) NULL, (char *) NULL,
	(char *) NULL}
};

/*
 * Forward declarations to procedures defined later in this file:
 */

static Tk_Window	CreateTopLevelWindow _ANSI_ARGS_((Tcl_Interp *interp,
			    Tk_Window parent, CONST char *name, 
			    CONST char *screenName, unsigned int flags));
static void		DeleteWindowsExitProc _ANSI_ARGS_((
			    ClientData clientData));
static TkDisplay *	GetScreen _ANSI_ARGS_((Tcl_Interp *interp,
			    CONST char *screenName, int *screenPtr));
static int		Initialize _ANSI_ARGS_((Tcl_Interp *interp));
static int		NameWindow _ANSI_ARGS_((Tcl_Interp *interp,
			    TkWindow *winPtr, TkWindow *parentPtr,
			    CONST char *name));
static void		UnlinkWindow _ANSI_ARGS_((TkWindow *winPtr));

/*
 *----------------------------------------------------------------------
 *
 * TkCloseDisplay --
 *	Closing the display can lead to order of deletion problems.
 *	We defer it until exit handling for Mac/Win, but since Unix can
 *	use many displays, try and clean it up as best as possible.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Resources associated with the display will be free.
 *	The display may not be referenced at all after this.
 *----------------------------------------------------------------------
 */

static void
TkCloseDisplay(TkDisplay *dispPtr)
{
    TkClipCleanup(dispPtr);

    if (dispPtr->name != NULL) {
	ckfree(dispPtr->name);
    }

    if (dispPtr->atomInit) {
	Tcl_DeleteHashTable(&dispPtr->nameTable);
	Tcl_DeleteHashTable(&dispPtr->atomTable);
	dispPtr->atomInit = 0;
    }

    if (dispPtr->errorPtr != NULL) {
	TkErrorHandler *errorPtr;
	for (errorPtr = dispPtr->errorPtr;
	     errorPtr != NULL;
	     errorPtr = dispPtr->errorPtr) {
	    dispPtr->errorPtr = errorPtr->nextPtr;
	    ckfree((char *) errorPtr);
	}
    }

    TkGCCleanup(dispPtr);

    TkpCloseDisplay(dispPtr);

    /*
     * Delete winTable after TkpCloseDisplay since special windows
     * may need call Tk_DestroyWindow and it checks the winTable.
     */

    Tcl_DeleteHashTable(&dispPtr->winTable);

    ckfree((char *) dispPtr);

    /*
     * There is more to clean up, we leave it at this for the time being.
     */
}

/*
 *----------------------------------------------------------------------
 *
 * CreateTopLevelWindow --
 *
 *	Make a new window that will be at top-level (its parent will
 *	be the root window of a screen).
 *
 * Results:
 *	The return value is a token for the new window, or NULL if
 *	an error prevented the new window from being created.  If
 *	NULL is returned, an error message will be left in
 *	the interp's result.
 *
 * Side effects:
 *	A new window structure is allocated locally.  An X
 *	window is NOT initially created, but will be created
 *	the first time the window is mapped.
 *
 *----------------------------------------------------------------------
 */

static Tk_Window
CreateTopLevelWindow(interp, parent, name, screenName, flags)
    Tcl_Interp *interp;		/* Interpreter to use for error reporting. */
    Tk_Window parent;		/* Token for logical parent of new window
				 * (used for naming, options, etc.).  May
				 * be NULL. */
    CONST char *name;		/* Name for new window;  if parent is
				 * non-NULL, must be unique among parent's
				 * children. */
    CONST char *screenName;	/* Name of screen on which to create
				 * window.  NULL means use DISPLAY environment
				 * variable to determine.  Empty string means
				 * use parent's screen, or DISPLAY if no
				 * parent. */
    unsigned int flags;		/* Additional flags to set on the window. */
{
    register TkWindow *winPtr;
    register TkDisplay *dispPtr;
    int screenId;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (!tsdPtr->initialized) {
	tsdPtr->initialized = 1;

	/*
	 * Create built-in image types.
	 */
    
	Tk_CreateImageType(&tkBitmapImageType);
	Tk_CreateImageType(&tkPhotoImageType);
    
	/*
	 * Create built-in photo image formats.
	 */
    
	Tk_CreatePhotoImageFormat(&tkImgFmtGIF);
	Tk_CreateOldPhotoImageFormat(&tkImgFmtPPM);

	/*
	 * Create exit handler to delete all windows when the application
	 * exits.
	 */

	TkCreateExitHandler(DeleteWindowsExitProc, (ClientData) tsdPtr);
    }

    if ((parent != NULL) && (screenName != NULL) && (screenName[0] == '\0')) {
	dispPtr = ((TkWindow *) parent)->dispPtr;
	screenId = Tk_ScreenNumber(parent);
    } else {
	dispPtr = GetScreen(interp, screenName, &screenId);
	if (dispPtr == NULL) {
	    return (Tk_Window) NULL;
	}
    }

    winPtr = TkAllocWindow(dispPtr, screenId, (TkWindow *) parent);

    /*
     * Set the flags specified in the call.
     */
    winPtr->flags |= flags;
    
    /*
     * Force the window to use a border pixel instead of border pixmap. 
     * This is needed for the case where the window doesn't use the
     * default visual.  In this case, the default border is a pixmap
     * inherited from the root window, which won't work because it will
     * have the wrong visual.
     */

    winPtr->dirtyAtts |= CWBorderPixel;

    /*
     * (Need to set the TK_TOP_HIERARCHY flag immediately here;  otherwise
     * Tk_DestroyWindow will core dump if it is called before the flag
     * has been set.)
     */

    winPtr->flags |= TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED;

    if (parent != NULL) {
        if (NameWindow(interp, winPtr, (TkWindow *) parent, name) != TCL_OK) {
	    Tk_DestroyWindow((Tk_Window) winPtr);
	    return (Tk_Window) NULL;
	}
    }
    TkWmNewWindow(winPtr);

    return (Tk_Window) winPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * GetScreen --
 *
 *	Given a string name for a display-plus-screen, find the
 *	TkDisplay structure for the display and return the screen
 *	number too.
 *
 * Results:
 *	The return value is a pointer to information about the display,
 *	or NULL if the display couldn't be opened.  In this case, an
 *	error message is left in the interp's result.  The location at
 *	*screenPtr is overwritten with the screen number parsed from
 *	screenName.
 *
 * Side effects:
 *	A new connection is opened to the display if there is no
 *	connection already.  A new TkDisplay data structure is also
 *	setup, if necessary.
 *
 *----------------------------------------------------------------------
 */

static TkDisplay *
GetScreen(interp, screenName, screenPtr)
    Tcl_Interp *interp;		/* Place to leave error message. */
    CONST char *screenName;	/* Name for screen.  NULL or empty means
				 * use DISPLAY envariable. */
    int *screenPtr;		/* Where to store screen number. */
{
    register TkDisplay *dispPtr;
    CONST char *p;
    int screenId;
    size_t length;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * Separate the screen number from the rest of the display
     * name.  ScreenName is assumed to have the syntax
     * <display>.<screen> with the dot and the screen being
     * optional.
     */

    screenName = TkGetDefaultScreenName(interp, screenName);
    if (screenName == NULL) {
	Tcl_SetResult(interp,
		"no display name and no $DISPLAY environment variable",
		TCL_STATIC);
	return (TkDisplay *) NULL;
    }
    length = strlen(screenName);
    screenId = 0;
    p = screenName+length-1;
    while (isdigit(UCHAR(*p)) && (p != screenName)) {
	p--;
    }
    if ((*p == '.') && (p[1] != '\0')) {
	length = p - screenName;
	screenId = strtoul(p+1, (char **) NULL, 10);
    }

    /*
     * See if we already have a connection to this display.  If not,
     * then open a new connection.
     */

    for (dispPtr = tsdPtr->displayList; ; dispPtr = dispPtr->nextPtr) {
	if (dispPtr == NULL) {
	    /*
	     * The private function zeros out dispPtr when it is created,
	     * so we only need to initialize the non-zero items.
	     */
	    dispPtr = TkpOpenDisplay(screenName);
	    if (dispPtr == NULL) {
		Tcl_AppendResult(interp, "couldn't connect to display \"",
			screenName, "\"", (char *) NULL);
		return (TkDisplay *) NULL;
	    }
	    dispPtr->nextPtr = tsdPtr->displayList; /* TkGetDisplayList(); */
	    tsdPtr->displayList = dispPtr;

	    dispPtr->lastEventTime = CurrentTime;
	    dispPtr->bindInfoStale = 1;
	    dispPtr->cursorFont = None;
	    dispPtr->warpWindow = None;
	    dispPtr->multipleAtom = None;
	    /*
	     * By default we do want to collapse motion events in
	     * Tk_QueueWindowEvent.
	     */
	    dispPtr->flags |= TK_DISPLAY_COLLAPSE_MOTION_EVENTS;

	    Tcl_InitHashTable(&dispPtr->winTable, TCL_ONE_WORD_KEYS);

	    dispPtr->name = (char *) ckalloc((unsigned) (length+1));
	    strncpy(dispPtr->name, screenName, length);
	    dispPtr->name[length] = '\0';

	    TkInitXId(dispPtr);
	    break;
	}
	if ((strncmp(dispPtr->name, screenName, length) == 0)
		&& (dispPtr->name[length] == '\0')) {
	    break;
	}
    }
    if (screenId >= ScreenCount(dispPtr->display)) {
	char buf[32 + TCL_INTEGER_SPACE];
	
	sprintf(buf, "bad screen number \"%d\"", screenId);
	Tcl_SetResult(interp, buf, TCL_VOLATILE);
	return (TkDisplay *) NULL;
    }
    *screenPtr = screenId;
    return dispPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkGetDisplay --
 *
 *	Given an X display, TkGetDisplay returns the TkDisplay 
 *      structure for the display.
 *
 * Results:
 *	The return value is a pointer to information about the display,
 *	or NULL if the display did not have a TkDisplay structure.
 *
 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */

TkDisplay *
TkGetDisplay(display)
     Display *display;          /* X's display pointer */
{
    TkDisplay *dispPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    for (dispPtr = tsdPtr->displayList; dispPtr != NULL;
	    dispPtr = dispPtr->nextPtr) {
	if (dispPtr->display == display) {
	    break;
	}
    }
    return dispPtr;
}

/*
 *--------------------------------------------------------------
 *
 * TkGetDisplayList --
 *
 *	This procedure returns a pointer to the thread-local
 *      list of TkDisplays corresponding to the open displays.
 *
 * Results:
 *	The return value is a pointer to the first TkDisplay
 *      structure in thread-local-storage.
 *
 * Side effects:
 *      None.
 *
 *--------------------------------------------------------------
 */
TkDisplay *
TkGetDisplayList()
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    
    return tsdPtr->displayList;
}

/*
 *--------------------------------------------------------------
 *
 * TkGetMainInfoList --
 *
 *	This procedure returns a pointer to the list of structures
 *      containing information about all main windows for the
 *      current thread.
 *
 * Results:
 *	The return value is a pointer to the first TkMainInfo
 *      structure in thread local storage.
 *
 * Side effects:
 *      None.
 *
 *--------------------------------------------------------------
 */
TkMainInfo *
TkGetMainInfoList()
{
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    
    return tsdPtr->mainWindowList;
}
/*
 *--------------------------------------------------------------
 *
 * TkAllocWindow --
 *
 *	This procedure creates and initializes a TkWindow structure.
 *
 * Results:
 *	The return value is a pointer to the new window.
 *
 * Side effects:
 *	A new window structure is allocated and all its fields are
 *	initialized.
 *
 *--------------------------------------------------------------
 */

TkWindow *
TkAllocWindow(dispPtr, screenNum, parentPtr)
    TkDisplay *dispPtr;		/* Display associated with new window. */
    int screenNum;		/* Index of screen for new window. */
    TkWindow *parentPtr;	/* Parent from which this window should
				 * inherit visual information.  NULL means
				 * use screen defaults instead of
				 * inheriting. */
{
    register TkWindow *winPtr;

    winPtr = (TkWindow *) ckalloc(sizeof(TkWindow));
    winPtr->display = dispPtr->display;
    winPtr->dispPtr = dispPtr;
    winPtr->screenNum = screenNum;
    if ((parentPtr != NULL) && (parentPtr->display == winPtr->display)
	    && (parentPtr->screenNum == winPtr->screenNum)) {
	winPtr->visual = parentPtr->visual;
	winPtr->depth = parentPtr->depth;
    } else {
	winPtr->visual = DefaultVisual(dispPtr->display, screenNum);
	winPtr->depth = DefaultDepth(dispPtr->display, screenNum);
    }
    winPtr->window = None;
    winPtr->childList = NULL;
    winPtr->lastChildPtr = NULL;
    winPtr->parentPtr = NULL;
    winPtr->nextPtr = NULL;
    winPtr->mainPtr = NULL;
    winPtr->pathName = NULL;
    winPtr->nameUid = NULL;
    winPtr->classUid = NULL;
    winPtr->changes = defChanges;
    winPtr->dirtyChanges = CWX|CWY|CWWidth|CWHeight|CWBorderWidth;
    winPtr->atts = defAtts;
    if ((parentPtr != NULL) && (parentPtr->display == winPtr->display)
	    && (parentPtr->screenNum == winPtr->screenNum)) {
	winPtr->atts.colormap = parentPtr->atts.colormap;
    } else {
	winPtr->atts.colormap = DefaultColormap(dispPtr->display, screenNum);
    }
    winPtr->dirtyAtts = CWEventMask|CWColormap|CWBitGravity;
    winPtr->flags = 0;
    winPtr->handlerList = NULL;
#ifdef TK_USE_INPUT_METHODS
    winPtr->inputContext = NULL;
#endif /* TK_USE_INPUT_METHODS */
    winPtr->tagPtr = NULL;
    winPtr->numTags = 0;
    winPtr->optionLevel = -1;
    winPtr->selHandlerList = NULL;
    winPtr->geomMgrPtr = NULL;
    winPtr->geomData = NULL;
    winPtr->reqWidth = winPtr->reqHeight = 1;
    winPtr->internalBorderLeft = 0;
    winPtr->wmInfoPtr = NULL;
    winPtr->classProcsPtr = NULL;
    winPtr->instanceData = NULL;
    winPtr->privatePtr = NULL;
    winPtr->internalBorderRight = 0;
    winPtr->internalBorderTop = 0;
    winPtr->internalBorderBottom = 0;
    winPtr->minReqWidth = 0;
    winPtr->minReqHeight = 0;

    return winPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * NameWindow --
 *
 *	This procedure is invoked to give a window a name and insert
 *	the window into the hierarchy associated with a particular
 *	application.
 *
 * Results:
 *	A standard Tcl return value.
 *
 * Side effects:
 *      See above.
 *
 *----------------------------------------------------------------------
 */

static int
NameWindow(interp, winPtr, parentPtr, name)
    Tcl_Interp *interp;		/* Interpreter to use for error reporting. */
    register TkWindow *winPtr;	/* Window that is to be named and inserted. */
    TkWindow *parentPtr;	/* Pointer to logical parent for winPtr
				 * (used for naming, options, etc.). */
    CONST char *name;		/* Name for winPtr;   must be unique among
				 * parentPtr's children. */
{
#define FIXED_SIZE 200
    char staticSpace[FIXED_SIZE];
    char *pathName;
    int new;
    Tcl_HashEntry *hPtr;
    int length1, length2;

    /*
     * Setup all the stuff except name right away, then do the name stuff
     * last.  This is so that if the name stuff fails, everything else
     * will be properly initialized (needed to destroy the window cleanly
     * after the naming failure).
     */
    winPtr->parentPtr = parentPtr;
    winPtr->nextPtr = NULL;
    if (parentPtr->childList == NULL) {
	parentPtr->childList = winPtr;
    } else {
	parentPtr->lastChildPtr->nextPtr = winPtr;
    }
    parentPtr->lastChildPtr = winPtr;
    winPtr->mainPtr = parentPtr->mainPtr;
    winPtr->mainPtr->refCount++;

    /*
     * If this is an anonymous window (ie, it has no name), just return OK
     * now.
     */
    if (winPtr->flags & TK_ANONYMOUS_WINDOW) {
	return TCL_OK;
    }

    /*
     * For non-anonymous windows, set up the window name.
     */

    winPtr->nameUid = Tk_GetUid(name);

    /*
     * Don't permit names that start with an upper-case letter:  this
     * will just cause confusion with class names in the option database.
     */

    if (isupper(UCHAR(name[0]))) {
	Tcl_AppendResult(interp,
		"window name starts with an upper-case letter: \"",
		name, "\"", (char *) NULL);
	return TCL_ERROR;
    }

    /*
     * To permit names of arbitrary length, must be prepared to malloc
     * a buffer to hold the new path name.  To run fast in the common
     * case where names are short, use a fixed-size buffer on the
     * stack.
     */

    length1 = strlen(parentPtr->pathName);
    length2 = strlen(name);
    if ((length1+length2+2) <= FIXED_SIZE) {
	pathName = staticSpace;
    } else {
	pathName = (char *) ckalloc((unsigned) (length1+length2+2));
    }
    if (length1 == 1) {
	pathName[0] = '.';
	strcpy(pathName+1, name);
    } else {
	strcpy(pathName, parentPtr->pathName);
	pathName[length1] = '.';
	strcpy(pathName+length1+1, name);
    }
    hPtr = Tcl_CreateHashEntry(&parentPtr->mainPtr->nameTable, pathName, &new);
    if (pathName != staticSpace) {
	ckfree(pathName);
    }
    if (!new) {
	Tcl_AppendResult(interp, "window name \"", name,
		"\" already exists in parent", (char *) NULL);
	return TCL_ERROR;
    }
    Tcl_SetHashValue(hPtr, winPtr);
    winPtr->pathName = Tcl_GetHashKey(&parentPtr->mainPtr->nameTable, hPtr);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * TkCreateMainWindow --
 *
 *	Make a new main window.  A main window is a special kind of
 *	top-level window used as the outermost window in an
 *	application.
 *
 * Results:
 *	The return value is a token for the new window, or NULL if
 *	an error prevented the new window from being created.  If
 *	NULL is returned, an error message will be left in
 *	the interp's result.
 *
 * Side effects:
 *	A new window structure is allocated locally;  "interp" is
 *	associated with the window and registered for "send" commands
 *	under "baseName".  BaseName may be extended with an instance
 *	number in the form "#2" if necessary to make it globally
 *	unique.  Tk-related commands are bound into interp.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
TkCreateMainWindow(interp, screenName, baseName)
    Tcl_Interp *interp;		/* Interpreter to use for error reporting. */
    CONST char *screenName;	/* Name of screen on which to create
				 * window.  Empty or NULL string means
				 * use DISPLAY environment variable. */
    char *baseName;		/* Base name for application;  usually of the
				 * form "prog instance". */
{
    Tk_Window tkwin;
    int dummy;
    int isSafe;
    Tcl_HashEntry *hPtr;
    register TkMainInfo *mainPtr;
    register TkWindow *winPtr;
    register TkCmd *cmdPtr;
    ClientData clientData;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    
    /*
     * Panic if someone updated the TkWindow structure without
     * also updating the Tk_FakeWin structure (or vice versa).
     */

    if (sizeof(TkWindow) != sizeof(Tk_FakeWin)) {
	Tcl_Panic("TkWindow and Tk_FakeWin are not the same size");
    }

    /*
     * Create the basic TkWindow structure.
     */

    tkwin = CreateTopLevelWindow(interp, (Tk_Window) NULL, baseName,
	    screenName, /* flags */ 0);
    if (tkwin == NULL) {
	return NULL;
    }
    
    /*
     * Create the TkMainInfo structure for this application, and set
     * up name-related information for the new window.
     */

    winPtr = (TkWindow *) tkwin;
    mainPtr = (TkMainInfo *) ckalloc(sizeof(TkMainInfo));
    mainPtr->winPtr = winPtr;
    mainPtr->refCount = 1;
    mainPtr->interp = interp;
    Tcl_InitHashTable(&mainPtr->nameTable, TCL_STRING_KEYS);
    mainPtr->deletionEpoch = 0l;
    TkEventInit();
    TkBindInit(mainPtr);
    TkFontPkgInit(mainPtr);
    TkStylePkgInit(mainPtr);
    mainPtr->tlFocusPtr = NULL;
    mainPtr->displayFocusPtr = NULL;
    mainPtr->optionRootPtr = NULL;
    Tcl_InitHashTable(&mainPtr->imageTable, TCL_STRING_KEYS);
    mainPtr->strictMotif = 0;
    if (Tcl_LinkVar(interp, "tk_strictMotif", (char *) &mainPtr->strictMotif,
	    TCL_LINK_BOOLEAN) != TCL_OK) {
	Tcl_ResetResult(interp);
    }
    mainPtr->nextPtr = tsdPtr->mainWindowList;
    tsdPtr->mainWindowList = mainPtr;
    winPtr->mainPtr = mainPtr;
    hPtr = Tcl_CreateHashEntry(&mainPtr->nameTable, ".", &dummy);
    Tcl_SetHashValue(hPtr, winPtr);
    winPtr->pathName = Tcl_GetHashKey(&mainPtr->nameTable, hPtr);

    /*
     * We have just created another Tk application; increment the refcount
     * on the display pointer.
     */

    winPtr->dispPtr->refCount++;

    /*
     * Register the interpreter for "send" purposes.
     */

    winPtr->nameUid = Tk_GetUid(Tk_SetAppName(tkwin, baseName));

    /*
     * Bind in Tk's commands.
     */

    isSafe = Tcl_IsSafe(interp);
    for (cmdPtr = commands; cmdPtr->name != NULL; cmdPtr++) {
	if ((cmdPtr->cmdProc == NULL) && (cmdPtr->objProc == NULL)) {
	    Tcl_Panic("TkCreateMainWindow: builtin command with NULL string and object procs");
	}
	if (cmdPtr->passMainWindow) {
	    clientData = (ClientData) tkwin;
	} else {
	    clientData = (ClientData) NULL;
	}
	if (cmdPtr->cmdProc != NULL) {
	    Tcl_CreateCommand(interp, cmdPtr->name, cmdPtr->cmdProc,
		    clientData, (void (*) _ANSI_ARGS_((ClientData))) NULL);
	} else {
	    Tcl_CreateObjCommand(interp, cmdPtr->name, cmdPtr->objProc,
		    clientData, NULL);
	}
        if (isSafe) {
            if (!(cmdPtr->isSafe)) {
                Tcl_HideCommand(interp, cmdPtr->name, cmdPtr->name);
            }
        }
    }

    TkCreateMenuCmd(interp);

    /*
     * Set variables for the intepreter.
     */

    Tcl_SetVar(interp, "tk_patchLevel", TK_PATCH_LEVEL, TCL_GLOBAL_ONLY);
    Tcl_SetVar(interp, "tk_version", TK_VERSION, TCL_GLOBAL_ONLY);

    tsdPtr->numMainWindows++;
    return tkwin;
}

/*
 *--------------------------------------------------------------
 *
 * Tk_CreateWindow --
 *
 *	Create a new internal or top-level window as a child of an
 *	existing window.
 *
 * Results:
 *	The return value is a token for the new window.  This
 *	is not the same as X's token for the window.  If an error
 *	occurred in creating the window (e.g. no such display or
 *	screen), then an error message is left in the interp's result and
 *	NULL is returned.
 *
 * Side effects:
 *	A new window structure is allocated locally.  An X
 *	window is not initially created, but will be created
 *	the first time the window is mapped.
 *
 *--------------------------------------------------------------
 */

Tk_Window
Tk_CreateWindow(interp, parent, name, screenName)
    Tcl_Interp *interp;		/* Interpreter to use for error reporting.
				 * the interp's result is assumed to be
				 * initialized by the caller. */
    Tk_Window parent;		/* Token for parent of new window. */
    CONST char *name;		/* Name for new window.  Must be unique
				 * among parent's children. */
    CONST char *screenName;	/* If NULL, new window will be internal on
				 * same screen as its parent.  If non-NULL,
				 * gives name of screen on which to create
				 * new window;  window will be a top-level
				 * window. */
{
    TkWindow *parentPtr = (TkWindow *) parent;
    TkWindow *winPtr;

    if ((parentPtr != NULL) && (parentPtr->flags & TK_ALREADY_DEAD)) {
	Tcl_AppendResult(interp,
		"can't create window: parent has been destroyed",
		(char *) NULL);
	return NULL;
    } else if ((parentPtr != NULL) &&
	    (parentPtr->flags & TK_CONTAINER)) {
	Tcl_AppendResult(interp,
		"can't create window: its parent has -container = yes",
		(char *) NULL);
	return NULL;
    }
    if (screenName == NULL) {
	winPtr = TkAllocWindow(parentPtr->dispPtr, parentPtr->screenNum,
		parentPtr);
	if (NameWindow(interp, winPtr, parentPtr, name) != TCL_OK) {
	    Tk_DestroyWindow((Tk_Window) winPtr);
	    return NULL;
	} else {
            return (Tk_Window) winPtr;
	}
    } else {
	return CreateTopLevelWindow(interp, parent, name, screenName,
		/* flags */ 0);
    }
}

/*
 *--------------------------------------------------------------
 *
 * Tk_CreateAnonymousWindow --
 *
 *	Create a new internal or top-level window as a child of an
 *	existing window; this window will be anonymous (unnamed), so
 *	it will not be visible at the Tcl level.
 *
 * Results:
 *	The return value is a token for the new window.  This
 *	is not the same as X's token for the window.  If an error
 *	occurred in creating the window (e.g. no such display or
 *	screen), then an error message is left in the interp's result and
 *	NULL is returned.
 *
 * Side effects:
 *	A new window structure is allocated locally.  An X
 *	window is not initially created, but will be created
 *	the first time the window is mapped.
 *
 *--------------------------------------------------------------
 */

Tk_Window
Tk_CreateAnonymousWindow(interp, parent, screenName)
    Tcl_Interp *interp;		/* Interpreter to use for error reporting.
				 * the interp's result is assumed to be
				 * initialized by the caller. */
    Tk_Window parent;		/* Token for parent of new window. */
    CONST char *screenName;	/* If NULL, new window will be internal on
				 * same screen as its parent.  If non-NULL,
				 * gives name of screen on which to create
				 * new window;  window will be a top-level
				 * window. */
{
    TkWindow *parentPtr = (TkWindow *) parent;
    TkWindow *winPtr;

    if ((parentPtr != NULL) && (parentPtr->flags & TK_ALREADY_DEAD)) {
	Tcl_AppendResult(interp,
		"can't create window: parent has been destroyed",
		(char *) NULL);
	return NULL;
    } else if ((parentPtr != NULL) &&
	    (parentPtr->flags & TK_CONTAINER)) {
	Tcl_AppendResult(interp,
		"can't create window: its parent has -container = yes",
		(char *) NULL);
	return NULL;
    }
    if (screenName == NULL) {
	winPtr = TkAllocWindow(parentPtr->dispPtr, parentPtr->screenNum,
		parentPtr);
	/*
	 * Add the anonymous window flag now, so that NameWindow will behave
	 * correctly.
	 */

	winPtr->flags |= TK_ANONYMOUS_WINDOW;
	if (NameWindow(interp, winPtr, parentPtr, (char *)NULL) != TCL_OK) {
	    Tk_DestroyWindow((Tk_Window) winPtr);
	    return NULL;
	}
	return (Tk_Window) winPtr;
    } else {
	return CreateTopLevelWindow(interp, parent, (char *)NULL, screenName,
		TK_ANONYMOUS_WINDOW);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_CreateWindowFromPath --
 *
 *	This procedure is similar to Tk_CreateWindow except that
 *	it uses a path name to create the window, rather than a
 *	parent and a child name.
 *
 * Results:
 *	The return value is a token for the new window.  This
 *	is not the same as X's token for the window.  If an error
 *	occurred in creating the window (e.g. no such display or
 *	screen), then an error message is left in the interp's result and
 *	NULL is returned.
 *
 * Side effects:
 *	A new window structure is allocated locally.  An X
 *	window is not initially created, but will be created
 *	the first time the window is mapped.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
Tk_CreateWindowFromPath(interp, tkwin, pathName, screenName)
    Tcl_Interp *interp;		/* Interpreter to use for error reporting.
				 * the interp's result is assumed to be
				 * initialized by the caller. */
    Tk_Window tkwin;		/* Token for any window in application
				 * that is to contain new window. */
    CONST char *pathName;	/* Path name for new window within the
				 * application of tkwin.  The parent of
				 * this window must already exist, but
				 * the window itself must not exist. */
    CONST char *screenName;	/* If NULL, new window will be on same
				 * screen as its parent.  If non-NULL,
				 * gives name of screen on which to create
				 * new window;  window will be a top-level
				 * window. */
{
#define FIXED_SPACE 5
    char fixedSpace[FIXED_SPACE+1];
    char *p;
    Tk_Window parent;
    int numChars;

    /*
     * Strip the parent's name out of pathName (it's everything up
     * to the last dot).  There are two tricky parts: (a) must
     * copy the parent's name somewhere else to avoid modifying
     * the pathName string (for large names, space for the copy
     * will have to be malloc'ed);  (b) must special-case the
     * situation where the parent is ".".
     */

    p = strrchr(pathName, '.');
    if (p == NULL) {
	Tcl_AppendResult(interp, "bad window path name \"", pathName,
		"\"", (char *) NULL);
	return NULL;
    }
    numChars = (int) (p-pathName);
    if (numChars > FIXED_SPACE) {
	p = (char *) ckalloc((unsigned) (numChars+1));
    } else {
	p = fixedSpace;
    }
    if (numChars == 0) {
	*p = '.';
	p[1] = '\0';
    } else {
	strncpy(p, pathName, (size_t) numChars);
	p[numChars] = '\0';
    }

    /*
     * Find the parent window.
     */

    parent = Tk_NameToWindow(interp, p, tkwin);
    if (p != fixedSpace) {
        ckfree(p);
    }
    if (parent == NULL) {
	return NULL;
    }
    if (((TkWindow *) parent)->flags & TK_ALREADY_DEAD) {
	Tcl_AppendResult(interp, 
	    "can't create window: parent has been destroyed", (char *) NULL);
	return NULL;
    } else if (((TkWindow *) parent)->flags & TK_CONTAINER) {
	Tcl_AppendResult(interp, 
	    "can't create window: its parent has -container = yes",
		(char *) NULL);
	return NULL;
    }

    /*
     * Create the window.
     */

    if (screenName == NULL) {
	TkWindow *parentPtr = (TkWindow *) parent;
	TkWindow *winPtr;

	winPtr = TkAllocWindow(parentPtr->dispPtr, parentPtr->screenNum,
		parentPtr);
	if (NameWindow(interp, winPtr, parentPtr, pathName+numChars+1)
		!= TCL_OK) {
	    Tk_DestroyWindow((Tk_Window) winPtr);
	    return NULL;
	} else {
	    return (Tk_Window) winPtr;
	}
    } else {
	return CreateTopLevelWindow(interp, parent, pathName+numChars+1,
		screenName, /* flags */ 0);
    }
}

/*
 *--------------------------------------------------------------
 *
 * Tk_DestroyWindow --
 *
 *	Destroy an existing window.  After this call, the caller
 *	should never again use the token. Note that this function
 *	can be reentered to destroy a window that was only
 *	partially destroyed before a call to exit.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The window is deleted, along with all of its children.
 *	Relevant callback procedures are invoked.
 *
 *--------------------------------------------------------------
 */

void
Tk_DestroyWindow(tkwin)
    Tk_Window tkwin;		/* Window to destroy. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkDisplay *dispPtr = winPtr->dispPtr;
    XEvent event;
    TkHalfdeadWindow *halfdeadPtr, *prev_halfdeadPtr;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
            Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (winPtr->flags & TK_ALREADY_DEAD) {
	/*
	 * A destroy event binding caused the window to be destroyed
	 * again.  Ignore the request.
	 */

	return;
    }
    winPtr->flags |= TK_ALREADY_DEAD;

    /*
     * Unless we are cleaning up a half dead
     * window from DeleteWindowsExitProc,
     * add this window to the half dead list.
     */

    if (tsdPtr->halfdeadWindowList &&
	    (tsdPtr->halfdeadWindowList->flags & HD_CLEANUP) &&
	    (tsdPtr->halfdeadWindowList->winPtr == winPtr)) {
	halfdeadPtr = tsdPtr->halfdeadWindowList;
    } else {
	halfdeadPtr = (TkHalfdeadWindow *) ckalloc(sizeof(TkHalfdeadWindow));
	halfdeadPtr->flags = 0;
	halfdeadPtr->winPtr = winPtr;
	halfdeadPtr->nextPtr = tsdPtr->halfdeadWindowList;
	tsdPtr->halfdeadWindowList = halfdeadPtr;
    }

    /*
     * Some cleanup needs to be done immediately, rather than later,
     * because it needs information that will be destoyed before we
     * get to the main cleanup point.  For example, TkFocusDeadWindow
     * needs to access the parentPtr field from a window, but if
     * a Destroy event handler deletes the window's parent this
     * field will be NULL before the main cleanup point is reached.
     */

    if (!(halfdeadPtr->flags & HD_FOCUS)) {
	halfdeadPtr->flags |= HD_FOCUS;
	TkFocusDeadWindow(winPtr);
    }

    /*
     * If this is a main window, remove it from the list of main
     * windows.  This needs to be done now (rather than later with
     * all the other main window cleanup) to handle situations where
     * a destroy binding for a window calls "exit".  In this case
     * the child window cleanup isn't complete when exit is called.
     * This situation is dealt with using the half dead window
     * list. Windows that are half dead gets cleaned up during exit.
     *
     * Also decrement the display refcount so that if this is the
     * last Tk application in this process on this display, the display
     * can be closed and its data structures deleted.
     */

    if (!(halfdeadPtr->flags & HD_MAIN_WIN) &&
	    winPtr->mainPtr != NULL && winPtr->mainPtr->winPtr == winPtr) {
	halfdeadPtr->flags |= HD_MAIN_WIN;
        dispPtr->refCount--;
	if (tsdPtr->mainWindowList == winPtr->mainPtr) {
	    tsdPtr->mainWindowList = winPtr->mainPtr->nextPtr;
	} else {
	    TkMainInfo *prevPtr;

	    for (prevPtr = tsdPtr->mainWindowList;
		    prevPtr->nextPtr != winPtr->mainPtr;
		    prevPtr = prevPtr->nextPtr) {
		/* Empty loop body. */
	    }
	    prevPtr->nextPtr = winPtr->mainPtr->nextPtr;
	}
	tsdPtr->numMainWindows--;
    }

    /*
     * Recursively destroy children. Note that this child
     * window block may need to be run multiple times
     * in the case where a child window has a Destroy
     * binding that calls exit.
     */

    if (!(halfdeadPtr->flags & HD_DESTROY_COUNT)) {
	halfdeadPtr->flags |= HD_DESTROY_COUNT;
	dispPtr->destroyCount++;
    }

    while (winPtr->childList != NULL) {
	TkWindow *childPtr;
	childPtr = winPtr->childList;
	childPtr->flags |= TK_DONT_DESTROY_WINDOW;
	Tk_DestroyWindow((Tk_Window) childPtr);
	if (winPtr->childList == childPtr) {
	    /*
	     * The child didn't remove itself from the child list, so
	     * let's remove it here.  This can happen in some strange
	     * conditions, such as when a Destroy event handler for a
	     * window destroys the window's parent.
	     */

	    winPtr->childList = childPtr->nextPtr;
	    childPtr->parentPtr = NULL;
	}
    }
    if ((winPtr->flags & (TK_CONTAINER|TK_BOTH_HALVES))
	    == (TK_CONTAINER|TK_BOTH_HALVES)) {
	/*
	 * This is the container for an embedded application, and
	 * the embedded application is also in this process.  Delete
	 * the embedded window in-line here, for the same reasons we
	 * delete children in-line (otherwise, for example, the Tk
	 * window may appear to exist even though its X window is
	 * gone; this could cause errors).  Special note: it's possible
	 * that the embedded window has already been deleted, in which
	 * case TkpGetOtherWindow will return NULL.
	 */

	TkWindow *childPtr;
	childPtr = TkpGetOtherWindow(winPtr);
	if (childPtr != NULL) {
	    childPtr->flags |= TK_DONT_DESTROY_WINDOW;
	    Tk_DestroyWindow((Tk_Window) childPtr);
	}
    }

    /*
     * Generate a DestroyNotify event.  In order for the DestroyNotify
     * event to be processed correctly, need to make sure the window
     * exists.  This is a bit of a kludge, and may be unnecessarily
     * expensive, but without it no event handlers will get called for
     * windows that don't exist yet.
     *
     * Note: if the window's pathName is NULL and the window is not an
     * anonymous window, it means that the window was not successfully
     * initialized in the first place, so we should not make the window exist
     * or generate the event.
     */

    if (!(halfdeadPtr->flags & HD_DESTROY_EVENT) &&
	    winPtr->pathName != NULL &&
	    !(winPtr->flags & TK_ANONYMOUS_WINDOW)) {
	halfdeadPtr->flags |= HD_DESTROY_EVENT;
	if (winPtr->window == None) {
	    Tk_MakeWindowExist(tkwin);
	}
	event.type = DestroyNotify;
	event.xdestroywindow.serial =
		LastKnownRequestProcessed(winPtr->display);
	event.xdestroywindow.send_event = False;
	event.xdestroywindow.display = winPtr->display;
	event.xdestroywindow.event = winPtr->window;
	event.xdestroywindow.window = winPtr->window;
	Tk_HandleEvent(&event);
    }

    /*
     * No additional bindings that could call exit
     * should be invoked from this point on,
     * so it is safe to remove this window
     * from the half dead list.
     */

    for (prev_halfdeadPtr = NULL,
	    halfdeadPtr = tsdPtr->halfdeadWindowList;
	    halfdeadPtr != NULL; ) {
	if (halfdeadPtr->winPtr == winPtr) {
	    if (prev_halfdeadPtr == NULL)
	        tsdPtr->halfdeadWindowList = halfdeadPtr->nextPtr;
	    else
	        prev_halfdeadPtr->nextPtr = halfdeadPtr->nextPtr;
	    ckfree((char *) halfdeadPtr);
	    break;
	}
	prev_halfdeadPtr = halfdeadPtr;
	halfdeadPtr = halfdeadPtr->nextPtr;
    }
    if (halfdeadPtr == NULL)
        Tcl_Panic("window not found on half dead list");

    /*
     * Cleanup the data structures associated with this window.
     */

    if (winPtr->flags & TK_WIN_MANAGED) {
	TkWmDeadWindow(winPtr);
    } else if (winPtr->flags & TK_WM_COLORMAP_WINDOW) {
	TkWmRemoveFromColormapWindows(winPtr);
    }
    if (winPtr->window != None) {
#if defined(MAC_OSX_TK) || defined(__WIN32__)
	XDestroyWindow(winPtr->display, winPtr->window);
#else
	if ((winPtr->flags & TK_TOP_HIERARCHY)
		|| !(winPtr->flags & TK_DONT_DESTROY_WINDOW)) {
	    /*
	     * The parent has already been destroyed and this isn't
	     * a top-level window, so this window will be destroyed
	     * implicitly when the parent's X window is destroyed;
	     * it's much faster not to do an explicit destroy of this
	     * X window.
	     */

	    dispPtr->lastDestroyRequest = NextRequest(winPtr->display);
	    XDestroyWindow(winPtr->display, winPtr->window);
	}
#endif
	TkFreeWindowId(dispPtr, winPtr->window);
	Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->winTable,
		(char *) winPtr->window));
	winPtr->window = None;
    }
    dispPtr->destroyCount--;
    UnlinkWindow(winPtr);
    TkEventDeadWindow(winPtr);
    TkBindDeadWindow(winPtr);
#ifdef TK_USE_INPUT_METHODS
    if (winPtr->inputContext != NULL) {
	XDestroyIC(winPtr->inputContext);
	winPtr->inputContext = NULL;
    }
#endif /* TK_USE_INPUT_METHODS */
    if (winPtr->tagPtr != NULL) {
	TkFreeBindingTags(winPtr);
    }
    TkOptionDeadWindow(winPtr);
    TkSelDeadWindow(winPtr);
    TkGrabDeadWindow(winPtr);
    if (winPtr->mainPtr != NULL) {
	if (winPtr->pathName != NULL) {
	    Tk_DeleteAllBindings(winPtr->mainPtr->bindingTable,
		    (ClientData) winPtr->pathName);
	    Tcl_DeleteHashEntry(Tcl_FindHashEntry(&winPtr->mainPtr->nameTable,
		    winPtr->pathName));
            /*
             * The memory pointed to by pathName has been deallocated.
             * Keep users from accessing it after the window has been
             * destroyed by setting it to NULL.
             */
            winPtr->pathName = NULL;

	    /*
	     * Invalidate all objects referring to windows
	     * with the same main window
	     */
	    winPtr->mainPtr->deletionEpoch++;
	}
	winPtr->mainPtr->refCount--;
	if (winPtr->mainPtr->refCount == 0) {
	    register TkCmd *cmdPtr;

	    /*
	     * We just deleted the last window in the application.  Delete
	     * the TkMainInfo structure too and replace all of Tk's commands
	     * with dummy commands that return errors.	Also delete the
	     * "send" command to unregister the interpreter.
	     *
	     * NOTE: Only replace the commands it if the interpreter is
	     * not being deleted. If it *is*, the interpreter cleanup will
	     * do all the needed work.
	     */

            if ((winPtr->mainPtr->interp != NULL) &&
                    (!Tcl_InterpDeleted(winPtr->mainPtr->interp))) {
                for (cmdPtr = commands; cmdPtr->name != NULL; cmdPtr++) {
                    Tcl_CreateCommand(winPtr->mainPtr->interp, cmdPtr->name,
                            TkDeadAppCmd, (ClientData) NULL,
                            (void (*) _ANSI_ARGS_((ClientData))) NULL);
                }
                Tcl_CreateCommand(winPtr->mainPtr->interp, "send",
                        TkDeadAppCmd, (ClientData) NULL, 
                        (void (*) _ANSI_ARGS_((ClientData))) NULL);
                Tcl_UnlinkVar(winPtr->mainPtr->interp, "tk_strictMotif");
            }
                
	    Tcl_DeleteHashTable(&winPtr->mainPtr->nameTable);
	    TkBindFree(winPtr->mainPtr);
	    TkDeleteAllImages(winPtr->mainPtr);
	    TkFontPkgFree(winPtr->mainPtr);
	    TkFocusFree(winPtr->mainPtr);
	    TkStylePkgFree(winPtr->mainPtr);

            /*
             * When embedding Tk into other applications, make sure 
             * that all destroy events reach the server. Otherwise
             * the embedding application may also attempt to destroy
             * the windows, resulting in an X error
             */

            if (winPtr->flags & TK_EMBEDDED) {
                XSync(winPtr->display, False); 
            }
	    ckfree((char *) winPtr->mainPtr);

            /*
             * If no other applications are using the display, close the
             * display now and relinquish its data structures.
             */

#if !defined(WIN32) && defined(NOT_YET)
            if (dispPtr->refCount <= 0) {
                /*
                 * I have disabled this code because on Windows there are
                 * still order dependencies in close-down. All displays
                 * and resources will get closed down properly anyway at
                 * exit, through the exit handler. -- jyl
                 */
		/*
		 * Ideally this should be enabled, as unix Tk can use multiple
		 * displays.  However, there are order issues still, as well
		 * as the handling of queued events and such that must be
		 * addressed before this can be enabled.  The current cleanup
		 * works except for send event issues. -- hobbs 04/2002
		 */
                
                TkDisplay *theDispPtr, *backDispPtr;
                
                /*
                 * Splice this display out of the list of displays.
                 */
                
                for (theDispPtr = tsdPtr->displayList, backDispPtr = NULL;
                         (theDispPtr != winPtr->dispPtr) &&
                             (theDispPtr != NULL);
                         theDispPtr = theDispPtr->nextPtr) {
                    backDispPtr = theDispPtr;
                }
                if (theDispPtr == NULL) {
                    Tcl_Panic("could not find display to close!");
                }
                if (backDispPtr == NULL) {
                    tsdPtr->displayList = theDispPtr->nextPtr;
                } else {
                    backDispPtr->nextPtr = theDispPtr->nextPtr;
                }

                /*
		 * Calling XSync creates X server traffic, but addresses a
		 * focus issue on close (but not the send issue). -- hobbs
		 XSync(dispPtr->display, True);
		 */

                /*
                 * Found and spliced it out, now actually do the cleanup.
                 */

		TkCloseDisplay(dispPtr);
            }
#endif
	}
    }
    Tcl_EventuallyFree((ClientData) winPtr, TCL_DYNAMIC);
}

/*
 *--------------------------------------------------------------
 *
 * Tk_MapWindow --
 *
 *	Map a window within its parent.  This may require the
 *	window and/or its parents to actually be created.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The given window will be mapped.  Windows may also
 *	be created.
 *
 *--------------------------------------------------------------
 */

void
Tk_MapWindow(tkwin)
    Tk_Window tkwin;		/* Token for window to map. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    XEvent event;

    if (winPtr->flags & TK_MAPPED) {
	return;
    }
    if (winPtr->window == None) {
	Tk_MakeWindowExist(tkwin);
    }
    if (winPtr->flags & TK_WIN_MANAGED) {
	/*
	 * Lots of special processing has to be done for top-level
	 * windows.  Let tkWm.c handle everything itself.
	 */

	TkWmMapWindow(winPtr);
	return;
    }
    winPtr->flags |= TK_MAPPED;
    XMapWindow(winPtr->display, winPtr->window);
    event.type = MapNotify;
    event.xmap.serial = LastKnownRequestProcessed(winPtr->display);
    event.xmap.send_event = False;
    event.xmap.display = winPtr->display;
    event.xmap.event = winPtr->window;
    event.xmap.window = winPtr->window;
    event.xmap.override_redirect = winPtr->atts.override_redirect;
    Tk_HandleEvent(&event);
}

/*
 *--------------------------------------------------------------
 *
 * Tk_MakeWindowExist --
 *
 *	Ensure that a particular window actually exists.  This
 *	procedure shouldn't normally need to be invoked from
 *	outside the Tk package, but may be needed if someone
 *	wants to manipulate a window before mapping it.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	When the procedure returns, the X window associated with
 *	tkwin is guaranteed to exist.  This may require the
 *	window's ancestors to be created also.
 *
 *--------------------------------------------------------------
 */

void
Tk_MakeWindowExist(tkwin)
    Tk_Window tkwin;		/* Token for window. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;
    TkWindow *winPtr2;
    Window parent;
    Tcl_HashEntry *hPtr;
    Tk_ClassCreateProc *createProc;
    int new;

    if (winPtr->window != None) {
	return;
    }

    if ((winPtr->parentPtr == NULL) || (winPtr->flags & TK_TOP_HIERARCHY)) {
	parent = XRootWindow(winPtr->display, winPtr->screenNum);
    } else {
	if (winPtr->parentPtr->window == None) {
	    Tk_MakeWindowExist((Tk_Window) winPtr->parentPtr);
	}
	parent = winPtr->parentPtr->window;
    }

    createProc = Tk_GetClassProc(winPtr->classProcsPtr, createProc);
    if (createProc != NULL) {
	winPtr->window = (*createProc)(tkwin, parent, winPtr->instanceData);
    } else {
	winPtr->window = TkpMakeWindow(winPtr, parent);
    }

    hPtr = Tcl_CreateHashEntry(&winPtr->dispPtr->winTable,
	    (char *) winPtr->window, &new);
    Tcl_SetHashValue(hPtr, winPtr);
    winPtr->dirtyAtts = 0;
    winPtr->dirtyChanges = 0;

    if (!(winPtr->flags & TK_TOP_HIERARCHY)) {
	/*
	 * 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_HIERARCHY|TK_REPARENTED))) {
		XWindowChanges changes;
		changes.sibling = winPtr2->window;
		changes.stack_mode = Below;
		XConfigureWindow(winPtr->display, winPtr->window,
			CWSibling|CWStackMode, &changes);
		break;
	    }
	}

	/*
	 * If this window has a different colormap than its parent, add
	 * the window to the WM_COLORMAP_WINDOWS property for its top-level.
	 */

	if ((winPtr->parentPtr != NULL) &&
		(winPtr->atts.colormap != winPtr->parentPtr->atts.colormap)) {
	    TkWmAddToColormapWindows(winPtr);
	    winPtr->flags |= TK_WM_COLORMAP_WINDOW;
	}
    }

    /*
     * 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;
	TkDoConfigureNotify(winPtr);
    }
}

/*
 *--------------------------------------------------------------
 *
 * Tk_UnmapWindow, etc. --
 *
 *	There are several procedures under here, each of which
 *	mirrors an existing X procedure.  In addition to performing
 *	the functions of the corresponding procedure, each
 *	procedure also updates the local window structure and
 *	synthesizes an X event (if the window's structure is being
 *	managed internally).
 *
 * Results:
 *	See the manual entries.
 *
 * Side effects:
 *	See the manual entries.
 *
 *--------------------------------------------------------------
 */

void
Tk_UnmapWindow(tkwin)
    Tk_Window tkwin;		/* Token for window to unmap. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    if (!(winPtr->flags & TK_MAPPED) || (winPtr->flags & TK_ALREADY_DEAD)) {
	return;
    }
    if (winPtr->flags & TK_WIN_MANAGED) {
	/*
	 * Special processing has to be done for top-level windows.  Let
	 * tkWm.c handle everything itself.
	 */

	TkWmUnmapWindow(winPtr);
	return;
    }
    winPtr->flags &= ~TK_MAPPED;
    XUnmapWindow(winPtr->display, winPtr->window);
    if (!(winPtr->flags & TK_TOP_HIERARCHY)) {
	XEvent event;

	event.type = UnmapNotify;
	event.xunmap.serial = LastKnownRequestProcessed(winPtr->display);
	event.xunmap.send_event = False;
	event.xunmap.display = winPtr->display;
	event.xunmap.event = winPtr->window;
	event.xunmap.window = winPtr->window;
	event.xunmap.from_configure = False;
	Tk_HandleEvent(&event);
    }
}

void
Tk_ConfigureWindow(tkwin, valueMask, valuePtr)
    Tk_Window tkwin;		/* Window to re-configure. */
    unsigned int valueMask;	/* Mask indicating which parts of
				 * *valuePtr are to be used. */
    XWindowChanges *valuePtr;	/* New values. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    if (valueMask & CWX) {
	winPtr->changes.x = valuePtr->x;
    }
    if (valueMask & CWY) {
	winPtr->changes.y = valuePtr->y;
    }
    if (valueMask & CWWidth) {
	winPtr->changes.width = valuePtr->width;
    }
    if (valueMask & CWHeight) {
	winPtr->changes.height = valuePtr->height;
    }
    if (valueMask & CWBorderWidth) {
	winPtr->changes.border_width = valuePtr->border_width;
    }
    if (valueMask & (CWSibling|CWStackMode)) {
	Tcl_Panic("Can't set sibling or stack mode from Tk_ConfigureWindow.");
    }

    if (winPtr->window != None) {
	XConfigureWindow(winPtr->display, winPtr->window,
		valueMask, valuePtr);
        TkDoConfigureNotify(winPtr);
    } else {
	winPtr->dirtyChanges |= valueMask;
	winPtr->flags |= TK_NEED_CONFIG_NOTIFY;
    }
}

void
Tk_MoveWindow(tkwin, x, y)
    Tk_Window tkwin;		/* Window to move. */
    int x, y;			/* New location for window (within
				 * parent). */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    winPtr->changes.x = x;
    winPtr->changes.y = y;
    if (winPtr->window != None) {
	XMoveWindow(winPtr->display, winPtr->window, x, y);
        TkDoConfigureNotify(winPtr);
    } else {
	winPtr->dirtyChanges |= CWX|CWY;
	winPtr->flags |= TK_NEED_CONFIG_NOTIFY;
    }
}

void
Tk_ResizeWindow(tkwin, width, height)
    Tk_Window tkwin;		/* Window to resize. */
    int width, height;		/* New dimensions for window. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    winPtr->changes.width = (unsigned) width;
    winPtr->changes.height = (unsigned) height;
    if (winPtr->window != None) {
	XResizeWindow(winPtr->display, winPtr->window, (unsigned) width,
		(unsigned) height);
        TkDoConfigureNotify(winPtr);
    } else {
	winPtr->dirtyChanges |= CWWidth|CWHeight;
	winPtr->flags |= TK_NEED_CONFIG_NOTIFY;
    }
}

void
Tk_MoveResizeWindow(tkwin, x, y, width, height)
    Tk_Window tkwin;		/* Window to move and resize. */
    int x, y;			/* New location for window (within
				 * parent). */
    int width, height;		/* New dimensions for window. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    winPtr->changes.x = x;
    winPtr->changes.y = y;
    winPtr->changes.width = (unsigned) width;
    winPtr->changes.height = (unsigned) height;
    if (winPtr->window != None) {
	XMoveResizeWindow(winPtr->display, winPtr->window, x, y,
		(unsigned) width, (unsigned) height);
        TkDoConfigureNotify(winPtr);
    } else {
	winPtr->dirtyChanges |= CWX|CWY|CWWidth|CWHeight;
	winPtr->flags |= TK_NEED_CONFIG_NOTIFY;
    }
}

void
Tk_SetWindowBorderWidth(tkwin, width)
    Tk_Window tkwin;		/* Window to modify. */
    int width;			/* New border width for window. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    winPtr->changes.border_width = width;
    if (winPtr->window != None) {
	XSetWindowBorderWidth(winPtr->display, winPtr->window,
		(unsigned) width);
        TkDoConfigureNotify(winPtr);
    } else {
	winPtr->dirtyChanges |= CWBorderWidth;
	winPtr->flags |= TK_NEED_CONFIG_NOTIFY;
    }
}

void
Tk_ChangeWindowAttributes(tkwin, valueMask, attsPtr)
    Tk_Window tkwin;		/* Window to manipulate. */
    unsigned long valueMask;	/* OR'ed combination of bits,
				 * indicating which fields of
				 * *attsPtr are to be used. */
    register XSetWindowAttributes *attsPtr;
				/* New values for some attributes. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    if (valueMask & CWBackPixmap) {
	winPtr->atts.background_pixmap = attsPtr->background_pixmap;
    }
    if (valueMask & CWBackPixel) {
	winPtr->atts.background_pixel = attsPtr->background_pixel;
    }
    if (valueMask & CWBorderPixmap) {
	winPtr->atts.border_pixmap = attsPtr->border_pixmap;
    }
    if (valueMask & CWBorderPixel) {
	winPtr->atts.border_pixel = attsPtr->border_pixel;
    }
    if (valueMask & CWBitGravity) {
	winPtr->atts.bit_gravity = attsPtr->bit_gravity;
    }
    if (valueMask & CWWinGravity) {
	winPtr->atts.win_gravity = attsPtr->win_gravity;
    }
    if (valueMask & CWBackingStore) {
	winPtr->atts.backing_store = attsPtr->backing_store;
    }
    if (valueMask & CWBackingPlanes) {
	winPtr->atts.backing_planes = attsPtr->backing_planes;
    }
    if (valueMask & CWBackingPixel) {
	winPtr->atts.backing_pixel = attsPtr->backing_pixel;
    }
    if (valueMask & CWOverrideRedirect) {
	winPtr->atts.override_redirect = attsPtr->override_redirect;
    }
    if (valueMask & CWSaveUnder) {
	winPtr->atts.save_under = attsPtr->save_under;
    }
    if (valueMask & CWEventMask) {
	winPtr->atts.event_mask = attsPtr->event_mask;
    }
    if (valueMask & CWDontPropagate) {
	winPtr->atts.do_not_propagate_mask
		= attsPtr->do_not_propagate_mask;
    }
    if (valueMask & CWColormap) {
	winPtr->atts.colormap = attsPtr->colormap;
    }
    if (valueMask & CWCursor) {
	winPtr->atts.cursor = attsPtr->cursor;
    }

    if (winPtr->window != None) {
	XChangeWindowAttributes(winPtr->display, winPtr->window,
		valueMask, attsPtr);
    } else {
	winPtr->dirtyAtts |= valueMask;
    }
}

void
Tk_SetWindowBackground(tkwin, pixel)
    Tk_Window tkwin;		/* Window to manipulate. */
    unsigned long pixel;	/* Pixel value to use for
				 * window's background. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    winPtr->atts.background_pixel = pixel;

    if (winPtr->window != None) {
	XSetWindowBackground(winPtr->display, winPtr->window, pixel);
    } else {
	winPtr->dirtyAtts = (winPtr->dirtyAtts & (unsigned) ~CWBackPixmap)
		| CWBackPixel;
    }
}

void
Tk_SetWindowBackgroundPixmap(tkwin, pixmap)
    Tk_Window tkwin;		/* Window to manipulate. */
    Pixmap pixmap;		/* Pixmap to use for window's
				 * background. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    winPtr->atts.background_pixmap = pixmap;

    if (winPtr->window != None) {
	XSetWindowBackgroundPixmap(winPtr->display,
		winPtr->window, pixmap);
    } else {
	winPtr->dirtyAtts = (winPtr->dirtyAtts & (unsigned) ~CWBackPixel)
		| CWBackPixmap;
    }
}

void
Tk_SetWindowBorder(tkwin, pixel)
    Tk_Window tkwin;		/* Window to manipulate. */
    unsigned long pixel;	/* Pixel value to use for
				 * window's border. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    winPtr->atts.border_pixel = pixel;

    if (winPtr->window != None) {
	XSetWindowBorder(winPtr->display, winPtr->window, pixel);
    } else {
	winPtr->dirtyAtts = (winPtr->dirtyAtts & (unsigned) ~CWBorderPixmap)
		| CWBorderPixel;
    }
}

void
Tk_SetWindowBorderPixmap(tkwin, pixmap)
    Tk_Window tkwin;		/* Window to manipulate. */
    Pixmap pixmap;		/* Pixmap to use for window's
				 * border. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    winPtr->atts.border_pixmap = pixmap;

    if (winPtr->window != None) {
	XSetWindowBorderPixmap(winPtr->display,
		winPtr->window, pixmap);
    } else {
	winPtr->dirtyAtts = (winPtr->dirtyAtts & (unsigned) ~CWBorderPixel)
		| CWBorderPixmap;
    }
}

void
Tk_DefineCursor(tkwin, cursor)
    Tk_Window tkwin;		/* Window to manipulate. */
    Tk_Cursor cursor;		/* Cursor to use for window (may be None). */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

#if defined(MAC_OSX_TK)
    winPtr->atts.cursor = (XCursor) cursor;
#else
    winPtr->atts.cursor = (Cursor) cursor;
#endif
    
    if (winPtr->window != None) {
	XDefineCursor(winPtr->display, winPtr->window, winPtr->atts.cursor);
    } else {
	winPtr->dirtyAtts = winPtr->dirtyAtts | CWCursor;
    }
}

void
Tk_UndefineCursor(tkwin)
    Tk_Window tkwin;		/* Window to manipulate. */
{
    Tk_DefineCursor(tkwin, None);
}

void
Tk_SetWindowColormap(tkwin, colormap)
    Tk_Window tkwin;		/* Window to manipulate. */
    Colormap colormap;		/* Colormap to use for window. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    winPtr->atts.colormap = colormap;

    if (winPtr->window != None) {
	XSetWindowColormap(winPtr->display, winPtr->window, colormap);
	if (!(winPtr->flags & TK_WIN_MANAGED)) {
	    TkWmAddToColormapWindows(winPtr);
	    winPtr->flags |= TK_WM_COLORMAP_WINDOW;
	}
    } else {
	winPtr->dirtyAtts |= CWColormap;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_SetWindowVisual --
 *
 *	This procedure is called to specify a visual to be used
 *	for a Tk window when it is created.  This procedure, if
 *	called at all, must be called before the X window is created
 *	(i.e. before Tk_MakeWindowExist is called).
 *
 * Results:
 *	The return value is 1 if successful, or 0 if the X window has
 *	been already created.
 *
 * Side effects:
 *	The information given is stored for when the window is created.
 *
 *----------------------------------------------------------------------
 */

int
Tk_SetWindowVisual(tkwin, visual, depth, colormap)
    Tk_Window tkwin;		/* Window to manipulate. */
    Visual *visual;		/* New visual for window. */
    int depth;			/* New depth for window. */
    Colormap colormap;		/* An appropriate colormap for the visual. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    if( winPtr->window != None ){
	/* Too late! */
	return 0;
    }

    winPtr->visual = visual;
    winPtr->depth = depth;
    winPtr->atts.colormap = colormap;
    winPtr->dirtyAtts |= CWColormap;

    /*
     * The following code is needed to make sure that the window doesn't
     * inherit the parent's border pixmap, which would result in a BadMatch
     * error.
     */

    if (!(winPtr->dirtyAtts & CWBorderPixmap)) {
	winPtr->dirtyAtts |= CWBorderPixel;
    }
    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * TkDoConfigureNotify --
 *
 *	Generate a ConfigureNotify event describing the current
 *	configuration of a window.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	An event is generated and processed by Tk_HandleEvent.
 *
 *----------------------------------------------------------------------
 */

void
TkDoConfigureNotify(winPtr)
    register TkWindow *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);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_SetClass --
 *
 *	This procedure is used to give a window a class.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A new class is stored for tkwin, replacing any existing
 *	class for it.
 *
 *----------------------------------------------------------------------
 */

void
Tk_SetClass(tkwin, className)
    Tk_Window tkwin;		/* Token for window to assign class. */
    CONST char *className;	/* New class for tkwin. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    winPtr->classUid = Tk_GetUid(className);
    if (winPtr->flags & TK_WIN_MANAGED) {
	TkWmSetClass(winPtr);
    }
    TkOptionClassChanged(winPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_SetClassProcs --
 *
 *	This procedure is used to set the class procedures and
 *	instance data for a window.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	A new set of class procedures and instance data is stored
 *	for tkwin, replacing any existing values.
 *
 *----------------------------------------------------------------------
 */

void
Tk_SetClassProcs(tkwin, procs, instanceData)
    Tk_Window tkwin;		/* Token for window to modify. */
    Tk_ClassProcs *procs;	/* Class procs structure. */
    ClientData instanceData;	/* Data to be passed to class procedures. */
{
    register TkWindow *winPtr = (TkWindow *) tkwin;

    winPtr->classProcsPtr = procs;
    winPtr->instanceData = instanceData;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_NameToWindow --
 *
 *	Given a string name for a window, this procedure
 *	returns the token for the window, if there exists a
 *	window corresponding to the given name.
 *
 * Results:
 *	The return result is either a token for the window corresponding
 *	to "name", or else NULL to indicate that there is no such
 *	window.  In this case, an error message is left in the interp's result.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
Tk_NameToWindow(interp, pathName, tkwin)
    Tcl_Interp *interp;		/* Where to report errors. */
    CONST char *pathName;	/* Path name of window. */
    Tk_Window tkwin;		/* Token for window:  name is assumed to
				 * belong to the same main window as tkwin. */
{
    Tcl_HashEntry *hPtr;

    if (tkwin == NULL) {
	/*
	 * Either we're not really in Tk, or the main window was destroyed and
	 * we're on our way out of the application
	 */
	Tcl_AppendResult(interp, "NULL main window", (char *)NULL);
	return NULL;
    }
    
    hPtr = Tcl_FindHashEntry(&((TkWindow *) tkwin)->mainPtr->nameTable,
	    pathName);
    if (hPtr == NULL) {
	Tcl_AppendResult(interp, "bad window path name \"",
		pathName, "\"", (char *) NULL);
	return NULL;
    }
    return (Tk_Window) Tcl_GetHashValue(hPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_IdToWindow --
 *
 *	Given an X display and window ID, this procedure returns the
 *	Tk token for the window, if there exists a Tk window corresponding
 *	to the given ID.
 *
 * Results:
 *	The return result is either a token for the window corresponding
 *	to the given X id, or else NULL to indicate that there is no such
 *	window.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
Tk_IdToWindow(display, window)
    Display *display;		/* X display containing the window. */
    Window window;		/* X window window id. */
{
    TkDisplay *dispPtr;
    Tcl_HashEntry *hPtr;

    for (dispPtr = TkGetDisplayList(); ; dispPtr = dispPtr->nextPtr) {
	if (dispPtr == NULL) {
	    return NULL;
	}
	if (dispPtr->display == display) {
	    break;
	}
    }

    hPtr = Tcl_FindHashEntry(&dispPtr->winTable, (char *) window);
    if (hPtr == NULL) {
	return NULL;
    }
    return (Tk_Window) Tcl_GetHashValue(hPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_DisplayName --
 *
 *	Return the textual name of a window's display.
 *
 * Results:
 *	The return value is the string name of the display associated
 *	with tkwin.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

CONST char *
Tk_DisplayName(tkwin)
    Tk_Window tkwin;		/* Window whose display name is desired. */
{
    return ((TkWindow *) tkwin)->dispPtr->name;
}

/*
 *----------------------------------------------------------------------
 *
 * 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;

    if (winPtr->parentPtr == NULL) {
	return;
    }
    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) {
		Tcl_Panic("UnlinkWindow couldn't find child in parent");
	    }
	}
	prevPtr->nextPtr = winPtr->nextPtr;
	if (winPtr->nextPtr == NULL) {
	    winPtr->parentPtr->lastChildPtr = prevPtr;
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_RestackWindow --
 *
 *	Change a window's position in the stacking order.
 *
 * Results:
 *	TCL_OK is normally returned.  If other is not a descendant
 *	of tkwin's parent then TCL_ERROR is returned and tkwin is
 *	not repositioned.
 *
 * Side effects:
 *	Tkwin is repositioned in the stacking order.
 *
 *----------------------------------------------------------------------
 */

int
Tk_RestackWindow(tkwin, aboveBelow, other)
    Tk_Window tkwin;		/* Token for window whose position in
				 * the stacking order is to change. */
    int aboveBelow;		/* Indicates new position of tkwin relative
				 * to other;  must be Above or Below. */
    Tk_Window other;		/* Tkwin will be moved to a position that
				 * puts it just above or below this window.
				 * If NULL then tkwin goes above or below
				 * all windows in the same parent. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkWindow *otherPtr = (TkWindow *) other;

    /*
     * Special case:  if winPtr is a top-level window then just find
     * the top-level ancestor of otherPtr and restack winPtr above
     * otherPtr without changing any of Tk's childLists.
     */

    if (winPtr->flags & TK_WIN_MANAGED) {
	while ((otherPtr != NULL) && !(otherPtr->flags & TK_TOP_HIERARCHY)) {
	    otherPtr = otherPtr->parentPtr;
	}
	TkWmRestackToplevel(winPtr, aboveBelow, otherPtr);
	return TCL_OK;
    }

    /*
     * Find an ancestor of otherPtr that is a sibling of winPtr.
     */

    if (winPtr->parentPtr == NULL) {
	/*
	 * Window is going to be deleted shortly;  don't do anything.
	 */

	return TCL_OK;
    }
    if (otherPtr == NULL) {
	if (aboveBelow == Above) {
	    otherPtr = winPtr->parentPtr->lastChildPtr;
	} else {
	    otherPtr = winPtr->parentPtr->childList;
	}
    } else {
	while (winPtr->parentPtr != otherPtr->parentPtr) {
	    if ((otherPtr == NULL) || (otherPtr->flags & TK_TOP_HIERARCHY)) {
		return TCL_ERROR;
	    }
	    otherPtr = otherPtr->parentPtr;
	}
    }
    if (otherPtr == winPtr) {
	return TCL_OK;
    }

    /*
     * Reposition winPtr in the stacking order.
     */

    UnlinkWindow(winPtr);
    if (aboveBelow == Above) {
	winPtr->nextPtr = otherPtr->nextPtr;
	if (winPtr->nextPtr == NULL) {
	    winPtr->parentPtr->lastChildPtr = winPtr;
	}
	otherPtr->nextPtr = winPtr;
    } else {
	TkWindow *prevPtr;

	prevPtr = winPtr->parentPtr->childList;
	if (prevPtr == otherPtr) {
	    winPtr->parentPtr->childList = winPtr;
	} else {
	    while (prevPtr->nextPtr != otherPtr) {
		prevPtr = prevPtr->nextPtr;
	    }
	    prevPtr->nextPtr = winPtr;
	}
	winPtr->nextPtr = otherPtr;
    }

    /*
     * Notify the X server of the change.  If winPtr hasn't yet been
     * created then there's no need to tell the X server now, since
     * the stacking order will be handled properly when the window
     * is finally created.
     */

    if (winPtr->window != None) {
	XWindowChanges changes;
	unsigned int mask;

	mask = CWStackMode;
	changes.stack_mode = Above;
	for (otherPtr = winPtr->nextPtr; otherPtr != NULL;
		otherPtr = otherPtr->nextPtr) {
	    if ((otherPtr->window != None)
		    && !(otherPtr->flags & (TK_TOP_HIERARCHY|TK_REPARENTED))){
		changes.sibling = otherPtr->window;
		changes.stack_mode = Below;
		mask = CWStackMode|CWSibling;
		break;
	    }
	}
	XConfigureWindow(winPtr->display, winPtr->window, mask, &changes);
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_MainWindow --
 *
 *	Returns the main window for an application.
 *
 * Results:
 *	If interp has a Tk application associated with it, the main
 *	window for the application is returned.  Otherwise NULL is
 *	returned and an error message is left in the interp's result.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

Tk_Window
Tk_MainWindow(interp)
    Tcl_Interp *interp;			/* Interpreter that embodies the
					 * application.  Used for error
					 * reporting also. */
{
    TkMainInfo *mainPtr;
    ThreadSpecificData *tsdPtr;

    if (interp == NULL) {
	return NULL;
    }
#ifdef USE_TCL_STUBS
    if (tclStubsPtr == NULL) {
	return NULL;
    }
#endif
    tsdPtr = (ThreadSpecificData *) 
	Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    for (mainPtr = tsdPtr->mainWindowList; mainPtr != NULL;
	    mainPtr = mainPtr->nextPtr) {
	if (mainPtr->interp == interp) {
	    return (Tk_Window) mainPtr->winPtr;
	}
    }
    Tcl_SetResult(interp, "this isn't a Tk application", TCL_STATIC);
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_StrictMotif --
 *
 *	Indicates whether strict Motif compliance has been specified
 *	for the given window.
 *
 * Results:
 *	The return value is 1 if strict Motif compliance has been
 *	requested for tkwin's application by setting the tk_strictMotif
 *	variable in its interpreter to a true value.  0 is returned
 *	if tk_strictMotif has a false value.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
Tk_StrictMotif(tkwin)
    Tk_Window tkwin;			/* Window whose application is
					 * to be checked. */
{
    return ((TkWindow *) tkwin)->mainPtr->strictMotif;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_GetNumMainWindows --
 *
 *	This procedure returns the number of main windows currently
 *	open in this process.
 *
 * Results:
 *	The number of main windows open in this process.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
Tk_GetNumMainWindows()
{
    ThreadSpecificData *tsdPtr;

#ifdef USE_TCL_STUBS
    if (tclStubsPtr == NULL) {
	return 0;
    }
#endif

    tsdPtr = (ThreadSpecificData *) 
	Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    return tsdPtr->numMainWindows;
}

/*
 *----------------------------------------------------------------------
 *
 * DeleteWindowsExitProc --
 *
 *	This procedure is invoked as an exit handler.  It deletes all
 *	of the main windows in the current thread. We really should
 *	be using a thread local exit handler to delete windows and a
 *	process exit handler to close the display but Tcl does
 *	not provide support for this usage.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
DeleteWindowsExitProc(clientData)
    ClientData clientData;		/* tsdPtr when handler was created. */
{
    TkDisplay *dispPtr, *nextPtr;
    Tcl_Interp *interp;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) clientData;

    /*
     * Finish destroying any windows that are in a
     * half-dead state. We must protect the interpreter
     * while destroying the window, because of <Destroy>
     * bindings which could destroy the interpreter
     * while the window is being deleted. This would
     * leave frames on the call stack pointing at
     * deleted memory, causing core dumps.
     */

    while (tsdPtr->halfdeadWindowList != NULL) {
        interp = tsdPtr->halfdeadWindowList->winPtr->mainPtr->interp;
        Tcl_Preserve((ClientData) interp);
        tsdPtr->halfdeadWindowList->flags |= HD_CLEANUP;
        tsdPtr->halfdeadWindowList->winPtr->flags &= ~TK_ALREADY_DEAD;
        Tk_DestroyWindow((Tk_Window) tsdPtr->halfdeadWindowList->winPtr);
        Tcl_Release((ClientData) interp);
    }

    /*
     * Destroy any remaining main windows.
     */

    while (tsdPtr->mainWindowList != NULL) {        
        interp = tsdPtr->mainWindowList->interp;
        Tcl_Preserve((ClientData) interp);
        Tk_DestroyWindow((Tk_Window) tsdPtr->mainWindowList->winPtr);
        Tcl_Release((ClientData) interp);
    }

    /*
     * Iterate destroying the displays until no more displays remain.
     * It is possible for displays to get recreated during exit by any
     * code that calls GetScreen, so we must destroy these new displays
     * as well as the old ones.
     */

    for (dispPtr = tsdPtr->displayList;
         dispPtr != NULL;
         dispPtr = tsdPtr->displayList) {
        /*
         * Now iterate over the current list of open displays, and first
         * set the global pointer to NULL so we will be able to notice if
         * any new displays got created during deletion of the current set.
         * We must also do this to ensure that Tk_IdToWindow does not find
         * the old display as it is being destroyed, when it wants to see
         * if it needs to dispatch a message.
         */

        for (tsdPtr->displayList = NULL; dispPtr != NULL; 
                dispPtr = nextPtr) {
            nextPtr = dispPtr->nextPtr;
            TkCloseDisplay(dispPtr);
        }
    }

    tsdPtr->numMainWindows = 0;
    tsdPtr->mainWindowList = NULL;
    tsdPtr->initialized = 0;
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_Init --
 *
 *	This procedure is invoked to add Tk to an interpreter.  It
 *	incorporates all of Tk's commands into the interpreter and
 *	creates the main window for a new Tk application.  If the
 *	interpreter contains a variable "argv", this procedure
 *	extracts several arguments from that variable, uses them
 *	to configure the main window, and modifies argv to exclude
 *	the arguments (see the "wish" documentation for a list of
 *	the arguments that are extracted).
 *
 * Results:
 *	Returns a standard Tcl completion code and sets the interp's result
 *	if there is an error.
 *
 * Side effects:
 *	Depends on various initialization scripts that get invoked.
 *
 *----------------------------------------------------------------------
 */

int
Tk_Init(interp)
    Tcl_Interp *interp;		/* Interpreter to initialize. */
{
    return Initialize(interp);
}

/*
 *----------------------------------------------------------------------
 *
 * Tk_SafeInit --
 *
 *	This procedure is invoked to add Tk to a safe interpreter. It
 *	invokes the internal procedure that does the real work.
 *
 * Results:
 *	Returns a standard Tcl completion code and sets the interp's result
 *	if there is an error.
 *
 * Side effects:
 *	Depends on various initialization scripts that are invoked.
 *
 *----------------------------------------------------------------------
 */

int
Tk_SafeInit(interp)
    Tcl_Interp *interp;		/* Interpreter to initialize. */
{
    /*
     * Initialize the interpreter with Tk, safely. This removes
     * all the Tk commands that are unsafe.
     *
     * Rationale:
     *
     * - Toplevel and menu are unsafe because they can be used to cover
     *   the entire screen and to steal input from the user.
     * - Continuous ringing of the bell is a nuisance.
     * - Cannot allow access to the clipboard because a malicious script
     *   can replace the contents with the string "rm -r *" and lead to
     *   surprises when the contents of the clipboard are pasted. Similarly,
     *   the selection command is blocked.
     * - Cannot allow send because it can be used to cause unsafe
     *   interpreters to execute commands. The tk command recreates the
     *   send command, so that too must be hidden.
     * - Focus can be used to grab the focus away from another window,
     *   in effect stealing user input. Cannot allow that.
     *   NOTE: We currently do *not* hide focus as it would make it
     *   impossible to provide keyboard input to Tk in a safe interpreter.
     * - Grab can be used to block the user from using any other apps
     *   on the screen.
     * - Tkwait can block the containing process forever. Use bindings,
     *   fileevents and split the protocol into before-the-wait and
     *   after-the-wait parts. More work but necessary.
     * - Wm is unsafe because (if toplevels are allowed, in the future)
     *   it can be used to remove decorations, move windows around, cover
     *   the entire screen etc etc.
     *
     * Current risks:
     *
     * - No CPU time limit, no memory allocation limits, no color limits.
     *
     *  The actual code called is the same as Tk_Init but Tcl_IsSafe()
     *  is checked at several places to differentiate the two initialisations.
     */

    return Initialize(interp);
}


extern TkStubs tkStubs;

/*
 *----------------------------------------------------------------------
 *
 * Initialize --
 *
 *
 * Results:
 *	A standard Tcl result. Also leaves an error message in the interp's
 *	result if there was an error.
 *
 * Side effects:
 *	Depends on the initialization scripts that are invoked.
 *
 *----------------------------------------------------------------------
 */

static int
Initialize(interp)
    Tcl_Interp *interp;		/* Interpreter to initialize. */
{
    char *p;
    int argc, code;
    CONST char **argv; 
    char *args[20];
    CONST char *argString = NULL;
    Tcl_DString class;
    ThreadSpecificData *tsdPtr;
    
    /*
     * Ensure that we are getting the matching version of Tcl.  This is
     * really only an issue when Tk is loaded dynamically.
     */

    if (Tcl_InitStubs(interp, TCL_VERSION, 1) == NULL) {
        return TCL_ERROR;
    }

    /*
     * Ensure that our obj-types are registered with the Tcl runtime.
     */
    TkRegisterObjTypes();

    tsdPtr = (ThreadSpecificData *) 
	Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    /*
     * Start by initializing all the static variables to default acceptable
     * values so that no information is leaked from a previous run of this
     * code.
     */

    Tcl_MutexLock(&windowMutex);
    synchronize = 0;
    name = NULL;
    display = NULL;
    geometry = NULL;
    colormap = NULL;
    use = NULL;
    visual = NULL;
    rest = 0;

    /*
     * We start by resetting the result because it might not be clean
     */
    Tcl_ResetResult(interp);

    if (Tcl_IsSafe(interp)) {
	/*
	 * Get the clearance to start Tk and the "argv" parameters
	 * from the master.
	 */
	Tcl_DString ds;
	
	/*
	 * Step 1 : find the master and construct the interp name
	 * (could be a function if new APIs were ok).
	 * We could also construct the path while walking, but there
	 * is no API to get the name of an interp either.
	 */
	Tcl_Interp *master = interp;

	while (1) {
	    master = Tcl_GetMaster(master);
	    if (master == NULL) {
		Tcl_AppendResult(interp, "NULL master", (char *) NULL);
		Tcl_MutexUnlock(&windowMutex);
		return TCL_ERROR;
	    }
	    if (!Tcl_IsSafe(master)) {
		/* Found the trusted master. */
		break;
	    }
	}
	/*
	 * Construct the name (rewalk...)
	 */
	if (Tcl_GetInterpPath(master, interp) != TCL_OK) {
	    Tcl_AppendResult(interp, "error in Tcl_GetInterpPath",
		    (char *) NULL);
	    Tcl_MutexUnlock(&windowMutex);
	    return TCL_ERROR;
	}
	/*
	 * Build the string to eval.
	 */
	Tcl_DStringInit(&ds);
	Tcl_DStringAppendElement(&ds, "::safe::TkInit");
	Tcl_DStringAppendElement(&ds, Tcl_GetStringResult(master));
	
	/*
	 * Step 2 : Eval in the master. The argument is the *reversed*
	 * interp path of the slave.
	 */
	
	if (Tcl_Eval(master, Tcl_DStringValue(&ds)) != TCL_OK) {
	    /*
	     * We might want to transfer the error message or not.
	     * We don't. (no API to do it and maybe security reasons).
	     */
	    Tcl_DStringFree(&ds);
	    Tcl_AppendResult(interp, 
		    "not allowed to start Tk by master's safe::TkInit",
		    (char *) NULL);
	    Tcl_MutexUnlock(&windowMutex);
	    return TCL_ERROR;
	}
	Tcl_DStringFree(&ds);
	/* 
	 * Use the master's result as argv.
	 * Note: We don't use the Obj interfaces to avoid dealing with
	 * cross interp refcounting and changing the code below.
	 */

	argString = Tcl_GetStringResult(master);
    } else {
	/*
	 * If there is an "argv" variable, get its value, extract out
	 * relevant arguments from it, and rewrite the variable without
	 * the arguments that we used.
	 */

	argString = Tcl_GetVar2(interp, "argv", (char *) NULL, TCL_GLOBAL_ONLY);
    }
    argv = NULL;
    if (argString != NULL) {
	char buffer[TCL_INTEGER_SPACE];

	if (Tcl_SplitList(interp, argString, &argc, &argv) != TCL_OK) {
	    argError:
	    Tcl_AddErrorInfo(interp,
		    "\n    (processing arguments in argv variable)");
	    Tcl_MutexUnlock(&windowMutex);
	    return TCL_ERROR;
	}
	if (Tk_ParseArgv(interp, (Tk_Window) NULL, &argc, argv,
		argTable, TK_ARGV_DONT_SKIP_FIRST_ARG|TK_ARGV_NO_DEFAULTS)
		!= TCL_OK) {
	    ckfree((char *) argv);
	    goto argError;
	}
	p = Tcl_Merge(argc, argv);
	Tcl_SetVar2(interp, "argv", (char *) NULL, p, TCL_GLOBAL_ONLY);
	sprintf(buffer, "%d", argc);
	Tcl_SetVar2(interp, "argc", (char *) NULL, buffer, TCL_GLOBAL_ONLY);
	ckfree(p);
    }

    /*
     * Figure out the application's name and class.
     */

    Tcl_DStringInit(&class);
    if (name == NULL) {
	int offset;
	TkpGetAppName(interp, &class);
	offset = Tcl_DStringLength(&class)+1;
	Tcl_DStringSetLength(&class, offset);
	Tcl_DStringAppend(&class, Tcl_DStringValue(&class), offset-1);
	name = Tcl_DStringValue(&class) + offset;
    } else {
	Tcl_DStringAppend(&class, name, -1);
    }

    p = Tcl_DStringValue(&class);
    if (*p) {
	Tcl_UtfToTitle(p);
    }

    /*
     * Create an argument list for creating the top-level window,
     * using the information parsed from argv, if any.
     */

    args[0] = "toplevel";